P(y∣x1,…,xn)=P(x1,…,xn)P(y)P(x1,…,xn∣y) Using the naive conditional independence assumption that
P(xi∣y,x1,…,xi−1,xi+1,…,xn)=P(xi∣y), for all i, this relationship is simplified to
P(y∣x1,…,xn)=P(x1,…,xn)P(y)∏i=1nP(xi∣y) Since P(x1,…,xn) is constant given the input,
we can use the following classification rule:
P(y∣x1,…,xn)∝P(y)i=1∏nP(xi∣y)⇓y^=argymaxP(y)i=1∏nP(xi∣y), and we can use Maximum A Posteriori (MAP) estimation to estimate
P(y) and P(xi∣y);
the former is then the relative frequency of class y
in the training set.
The different naive Bayes classifiers differ mainly by the assumptions they
make regarding the distribution of P(xi∣y).
In spite of their apparently over-simplified assumptions, naive Bayes
classifiers have worked quite well in many real-world situations, famously
document classification and spam filtering. They require a small amount
of training data to estimate the necessary parameters. (For theoretical
reasons why naive Bayes works well, and on which types of data it does, see
the references below.)
Naive Bayes learners and classifiers can be extremely fast compared to more
sophisticated methods.
The decoupling of the class conditional feature distributions means that each
distribution can be independently estimated as a one-dimensional distribution.
This in turn helps to alleviate problems stemming from the curse of
dimensionality.
On the flip side, although naive Bayes is known as a decent classifier,
it is known to be a bad estimator, so the probability outputs from
predict_proba are not to be taken too seriously.
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.5
,
random_state
=
0
)
gnb
=
GaussianNB
()
y_pred
=
gnb
.
fit
(
X_train
,
y_train
)
.
predict
(
X_test
)
print
(
"Number of mislabeled points out of a total
%d
points :
%d
"
%
(
X_test
.
shape
[
0
],
(
y_test
!=
y_pred
)
.
sum
()))
Number of mislabeled points out of a total 75 points : 4
Ny=∑i=1nNyi α=∑iαi where Ntic=∣{j∈J∣xij=t,yj=c}∣ is the number
of times category t appears in the samples xi, which belong
to class c, Nc=∣{j∈J∣yj=c}∣ is the number
of samples with class c, α is a smoothing parameter and
ni is the number of available categories of feature i.