Learning P (Y | x) for classification, calculating P (Y | x) under the new x condition, and then determining which class X should belong.
I have never figured out the number of parameters to be estimated for the calculation of P (Y | X), which is actually like this:
Here we assume that X = (x1, x2,..., xn), XI and Y are binary random variables, that is, XI and y take only one value in 0 and 1. For example, if X = (x1, x2), the parameters to be estimated are:
P (y = 1 | X1 = 0, X2 = 0), P (y = 1 | X1 = 0, X2 = 1), P (y = 1 | X1 = 1, x2 = 0), P (y = 1 | X1 = 1, X2 = 1), you need to calculate these four in total, because P (y = 0 | X) = 1-P (y = 1 | X), for example, P (y = 1 | X1 = 0, X2 = 0) = P, P (y = 0 | X1 = 0, X2 = 0) = 1-P, so we need to estimate 2 ^ N parameters in total. For a new X, you can determine which class it belongs to. However, if n is large, there are too many parameters to estimate. For example, n is usually large in document classification. If n = 50000, the estimated parameter is 2 ^ 50000. (In this example, P (y = 1 | X1 = 1,
X2 = 0) = P (y = 1, X1 = 1, X2 = 0)/(P (y = 1, X1 = 1, X2 = 0) + P (y = 0, X1 = 1, X2 = 0 )))
Then we thought of the Bayesian formula:
P (Y | X) = p (x | Y) P (y)/P (x)
In this case, the parameter to be calculated for P (x | Y = 0) is 2 ^ n-1, because the last one can be obtained from the sum above 1-since y can take two values, therefore, for P (x | Y), the number of parameters to be calculated is 2 (2 ^ N-1), and for P (Y), 1 is calculated, the other one can be obtained from the one that has been calculated from 1-. The total number of parameters to be calculated is 2 (2 ^ N-1) + 1, which is still terrible. (P (x) is usually not computed ).
Therefore, the condition independence (conditional independence) in Naive Bayes comes out, and X is independent of Y. If p (x | y, z) = p (x | z ), that is to say, given Z, the probability of X is irrelevant to whether y exists. Therefore:
P (x1, x2, X3 | y) = P (X1 | Y) P (X2, X3 | y, X1) = P (X1 | Y) P (X2 | y, x1) P (X3 | y, x1, x2) = P (X1 | Y) P (X2 | Y) P (X3 | Y), so P (x1, x2 ,..., XN | y) = P (X1 | Y) P (X2 | Y )... P (XN | Y)
So the parameter to be estimated is changed to 2n + 1. (Maybe I don't know why it's not 2 (n-1) + 1. Let's just take a look at some examples)
This greatly reduces the parameters to be estimated. Alas, this problem has been plagued for a long time, haha ~~
Here is a specific example to illustrate the number of parameters to be estimated under conditional independence (CMU machine learning homework ).
The class mark y can be set to {T, f}, x = <x1, x2 ,..., XN>, X1 is Boolean, {X2 ,..., xn} is a continuous variable. Assume that for each continuous variable XI, p (XI | Y) is subject to Gaussian distribution. Calculate the number of parameters to be estimated for classifying a new x using Naive Bayes.
Naive Bayes needs to calculate P (Y) and P (XI | y) (I = 1, 2 ,..., n), to calculate P (Y), you need to calculate one, because P (y = T) = 1-P (y = f); to calculate P (X1 | Y ), calculate P (x1 = T | Y = T) and P (x1 = T | Y = f) Because P (x1 = f | Y = T) = 1-P (x1 = T | Y = T), P (x1 = f | Y = f) = 1-P (X1 = T | Y = F ); to calculate P (XI | Y) calculate the expected values of Xi | y under y = T and Y = F: E [XI | Y = y] and variance E [(Xi-E (XI )) ^ 2 | Y = y], the number of parameters to be estimated in this step is 2*2 * (n-1), because 2 to N have a total of N-1 Xi. In summary, in order to classify a new X, the number of parameters to be calculated is: 1 + 2 + 2*2 * (n-1)
= 4n-1.