Main Content

天真的贝叶斯分类

这naive Bayes classifier is designed for use when predictors are independent of one another within each class, but it appears to work well in practice even when that independence assumption is not valid. It classifies data in two steps:

  1. 训练步骤:使用训练数据,该方法estimates the parameters of a probability distribution, assuming predictors are conditionally independent given the class.

  2. prediction step: For any unseen test data, the method computes the posterior probability of that sample belonging to each class. The method then classifies the test data according the largest posterior probability.

这class-conditional independence assumption greatly simplifies the training step since you can estimate the one-dimensional class-conditional density for each predictor individually. While the class-conditional independence between predictors is not true in general, research shows that this optimistic assumption works well in practice. This assumption of class-conditional independence of the predictors allows the naive Bayes classifier to estimate the parameters required for accurate classification while using less training data than many other classifiers. This makes it particularly effective for data sets containing many predictors.

金宝app支持的分布

这training step in naive Bayes classification is based on estimatingp((X|y), the probability or probability density of predictorsXgiven classy。天真的贝叶斯分类模型分类and training functionfitcnbprovide support for normal (Gaussian), kernel, multinomial, and multivariate, multinomial predictor conditional distributions. To specify distributions for the predictors, use the分销名称name-value pair argument offitcnb。您可以通过提供与分布名相对应的字符向量或字符串标量来指定所有预测变量的分布,或通过提供长度来指定预测变量的不同分布d字符串数组或字符向量的单元格数组,其中dis the number of predictors (that is, the number of columns ofX)。

正常(高斯)分布

'普通的'distribution (specify using'普通的') is appropriate for predictors that have normal distributions in each class. For each predictor you model with a normal distribution, the naive Bayes classifier estimates a separate normal distribution for each class by computing the mean and standard deviation of the training data in that class.

内核分布

'kernel'distribution (specify using'kernel') is appropriate for predictors that have a continuous distribution. It does not require a strong assumption such as a normal distribution and you can use it in cases where the distribution of a predictor may be skewed or have multiple peaks or modes. It requires more computing time and more memory than the normal distribution. For each predictor you model with a kernel distribution, the naive Bayes classifier computes a separate kernel density estimate for each class based on the training data for that class. By default the kernel is the normal kernel, and the classifier selects a width automatically for each class and predictor. The software supports specifying different kernels for each predictor, and different widths for each predictor or class.

多元多项式分布

多元,多项式分布(使用'mvmn')适用于观察结果的预测变量。下面描述了使用多元多元预测变量使用多元多元预测器的天真贝叶斯分类器结构。为了说明这些步骤,请考虑一个示例,其中观测值标记为0、1或2,并预测进行样品时的天气。

  1. 记录整个预测指标观察中表示的不同类别。例如,不同的类别(或预测级别)可能包括阳光,雨,雪和多云。

  2. 独立的观测响应类。对eXample, segregate observations labeled 0 from observations labeled 1 and 2, and observations labeled 1 from observations labeled 2.

  3. 对each response class, fit a multinomial model using the category relative frequencies and total number of observations. For example, for observations labeled 0, the estimated probability it was sunny is p s n n y | 0 =((n你mber of sunny observations with label 0)/(number of observations with label 0), and similar for the other categories and response labels.

类别条件的多项式随机变量包含多元多元式随机变量。

以下是使用多元多元元素的天真贝叶斯分类器的其他属性。

  • 对于每个预测指标,您可以用多元多项式分布进行建模,幼稚的贝叶斯分类器:

    • 记录每个预测变量的单独的一组不同的预测级

    • Computes a separate set of probabilities for the set of predictor levels for each class.

  • 这software supports modeling continuous predictors as multivariate multinomial. In this case, the predictor levels are the distinct occurrences of a measurement. This can lead a predictor having many predictor levels. It is good practice to discretize such predictors.

如果一个nobservation是固定数量的独立试验中的各种类别(由所有预测变量表示)的一组成功,然后指定预测因子包含多项式分布。有关详细信息,请参阅Multinomial Distribution

Multinomial Distribution

这m你ltinomial distribution (specify using'DistributionNames','mn')当给予班级时,是合适的observation是多项式随机变量。也就是说,观察或行,j预测数据数据Xrepresentsd类别,哪里Xjd是类别的成功次数(即预测指标)d n j = d = 1 d X j d 在dependent trials. The steps to train a naive Bayes classifier are outlined next.

  1. 对each class, fit a multinomial distribution for the predictors given the class by:

    1. Aggregating the weighted, category counts over all observations. Additionally, the software implements additive smoothing[1]

    2. 估计dcategory probabilities within each class using the aggregated category counts. These category probabilities compose the probability parameters of the multinomial distribution.

  2. Let a new observation have a total count ofm。然后,天真的贝叶斯分类器:

    1. 将每个多项式分布的总计数参数设置为m

    2. 对于每个类

    3. 预测与最高后概率相对应的类中的观察结果

考虑所谓的tok袋模型,那里有一个包含许多不同类型和比例的袋子的袋子。每个预测因子代表袋中的一种独特类型的令牌,一个观察是n在dependent draws (i.e., with replacement) of tokens from the bag, and the data is a vector of counts, where elementd是令牌的次数dappears.

机器学习应用程序是电子邮件垃圾邮件分类器的构造,每个预测因子代表单词,字符或短语(即令牌),观察是一封电子邮件,并且数据是电子邮件中的代币计数。一个预测因子可能会计算感叹点的数量,另一个预测因子可能会计算出“货币”一词的次数,而另一个可能会计算出接收者名称出现的次数。这是一个幼稚的贝叶斯模型,在进一步的假设中,令牌总数(或文档总长度)独立于响应类别。

Other properties of naive Bayes classifiers that use multinomial observations include:

  • 分类is based on the relative frequencies of the categories. Ifnj= 0进行观察j, then classification is not possible for that observation.

  • 预测因素不是有条件独立的,因为它们必须汇总到nj

  • 天真的贝叶斯is not appropriate whennjprovides information about the class. That is, this classifier requires thatnj独立于班级。

  • If you specify that the predictors are conditionally multinomial, then the software applies this specification to all predictors. In other words, you cannot include'Mn'指定时在单元格数组中'DistributionNames'

如果一个predictor是分类的,即在响应类中是多种元素,然后指定其是多元多种元素。有关详细信息,请参阅多元多项式分布

References

[1] Manning,C。D.,P。Raghavan和M.Schütze。信息检索简介, NY: Cambridge University Press, 2008.

也可以看看

功能

对象

Related Topics