Plot the decision boundary for Bayes

721 Views Asked by At

Let $X=(X_1,X_2) \in [0,1]×[0,1]$ and $Y \sim Bernoulli(p=X_1⋅X_2)$. The Bayes decision boundary $\{(x_1,x_2):P(Y=1|X=(x_1,x_2))=0.5\}$ in the regions $[0,1]×[0,1]$ whose points would be classified as $0$ and $1$.

The goal of this problem is to plot Bayes decision boundary and identify it in the above region.

I would appreciate it if someone will get me started on this problem.

I have been trying to do it in R (it is not necessarily using software) so I can visualize the problem, here is what I have so far:

n <- 10; a <- 0; b <- 1
x1 <- runif(n,a,b)
x2 <- runif(n,a,b)
p <- x1*x2
y <- ifelse(p > 0.50,1,0)

or should my x1 and x2 look like this :

 n <- 10
 x1 <- sample(0:1,n,replace = T)
 x2 <- sample(0:1,n,replace = T)
 p <- x1*x2
 y <- ifelse(p > 0.50,1,0)
2

There are 2 best solutions below

0
On

The bayes decision boundary is the set of points at which the probability of $Y=1$ given the values of $X_1, X_2$ is equal to 1/2:

$$P(Y=1 | X_1, X_2) = P(U>X_1X_2) = 1-X_1X_2$$

Where $U \sim Uni[0, 1]$ by the definition of $Y$. Set this equal to 1/2 and solve for $X_1$ in terms of $X_2$.

In python:

x1 = np.random.rand(1000)
x2 = np.random.rand(1000)
plt.scatter(x1, x2, c=(x1*x2 < 0.5))
plt.show()
0
On

It is very unclear what a Bernoulli distribution has to do with your question, if anything. Is seems that you simply want to plot $y = x_1 x_2$ and mark where $y=0.5$.... right?

enter image description here

Perhaps this is more graphical flair than you need, but in Mathematica:

Show[{
  Plot3D[x y, 
   {x, 0, 1}, {y, 0, 1},
   MeshFunctions -> {#3 &},
   Mesh -> 1,
   MeshStyle -> {Thickness[0.01], Red},
   PlotStyle -> Lighter[Blue]
   ],
  Graphics3D[{Opacity[0.5], 
    InfinitePlane[{0, 0, 1/2}, {{1, 0, 0}, {0, 1, 0}}]}]}]

The "bare bones" plot:

enter image description here

DensityPlot[If[x y > .5, 1, 0],
 {x, 0, 1}, {y, 0, 1}]