Bayes' theorem on continuous interval

88 Views Asked by At

I'm reading up on naive Bayes' classifiers, and it's just an application of Bayes' theorem. Which makes sense in a discrete space; example: counting the number of apples versus oranges, and predicting the probability of the next fruit being an orange given the previous counts and the fact that it's red: P(apple|red) = P(apples)*p(red|apple)/P(red)

But what about if I'm predicting something based on a measurement? Like, instead of red, I check its weight. For any weight, P(weight) = 0, since it's a real number right? How do I work around that?

2

There are 2 best solutions below

0
On

In general, you're interested in the posterior distribution of apple given weight.

For shorthand, defining $ A := \text{fruit is apple} $ and $ W := \text{weight} $, we have

$$ P(A \mid W) = \frac{P(W \mid A)P(A)}{P(W)} $$

where in this case, $ P(W) $ denotes the marginal density function of weight across all fruits, and $ P(W \mid A) $ is the distribution of weight of fruit conditioned on the fruit being an apple. $ P(A) $ is as usual, the probability that the fruit is an apple.

Then, you can simply evaluate this function at whether $A $ is an apple or orange, and use your estimated marginal density for $ W $ and estimated conditional density for $ W \mid A $.

Estimating these densities is another question entirely!

2
On

You can only deal with the conditional probability of an interval if the rancdom variable is continuous. Suppose you have two classes ($C$) of apples, "small apples" (x) and "big apples" (y). Their weights, and , are (approximately) normally distributed as follows:

$W_x\sim \mathcal N(75, 100), W_y\sim \mathcal N(200, 100)$

You know the proportion of small apples is $\frac23$. Now you select an apple. You know that the apple weighs between 70g and 150g. You want two know the probabilty that this apple is a "small apple". Now you can use the bayes theorem.

$P(C=x|70<W<150)=\frac{P(70<W<150) |C=x)\cdot P(C=x)}{P(70<W<150)}$

This probabilty can be calculculated easily. But if the weight of the selected apple would be exact $100g$ then we couldn´t calculate $P(C=x|W=100)$ since on the RHS the denominator would be $P(W=100)=0$.