由7.1可得 R(c∣x)=λ1P(c∣x)+λ2P($ \overline c$∣x)
R(c∣x)=λ1P(c∣x)+λ2P($ \overline c$∣x)
由7.4可得 R(c∣x)=P($ \overline c$∣x)
R(c∣x)=P($ \overline c$∣x)
求得7.5 R(c∣x)=1−P(∣x)
R(c∣x)=1−P(c∣x)
最小化误差,也就是最大化P(c|x),但由于P(c|x)属于后验概率无法直接计算,由贝叶斯公式可计算出: $$P(c|x)=P(x|c)*P(c)/P(x)$$ P(x)可以省略,因为我们比较的时候P(x)一定是相同的,所以我们就是用历史数据计算出P(c)和P(x|c)。
当样本属性独依赖时,也就是除了c多加一个依赖条件,式子变成了 $$∏_{i=1}^n(P(x_i|c,p_i))$$ $p_i$是$x_i$所依赖的属性
当样本属性相关性未知时,我们采用贝叶斯网的算法,对相关性进行评估,以找出一个最佳的分类模型。
当遇到不完整的训练样本时,可通过使用EM算法对模型参数进行评估来解决。
①sklearn调包
import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
GaussianNB(priors=None, var_smoothing=1e-09)
print(clf.predict([[-0.8, -1]]))
②sklearn参数: priors : array-like, shape (n_classes,) Prior probabilities of the classes. If specified the priors are not adjusted according to the data.
var_smoothing : float, optional (default=1e-9) Portion of the largest variance of all features that is added to variances for calculation stability.