朴素贝叶斯分类器(Python实现+详细源码原理)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了朴素贝叶斯分类器(Python实现+详细源码原理)相关的知识,希望对你有一定的参考价值。
参考技术A1、贝叶斯公式的本质: <u>由因到果,由果推因</u>
2、贝叶斯公式:
[图片上传中...(wps6.png-5fd624-1618488341725-0)]
1、朴素贝叶斯公式
x1,x2,...xn为特征集合,y为分类结果
朴素贝叶斯假设各个特征之间相互独立
分母相同情况下,我们只要保证分子最大
训练数据集
long,not_long,sweet,not_sweet,yellow,not_yellow,species
400,100,350,150,450,50,banana
0,300,150,150,300,0,orange
100,100,150,50,50,150,other_fruit
测试数据集
long,sweet,yellow
not_long,not_sweet,not_yellow
not_long,sweet,not_yellow
not_long,sweet,yellow
not_long,sweet,yellow
not_long,not_sweet,not_yellow
long,not_sweet,not_yellow
long,not_sweet,not_yellow
long,not_sweet,not_yellow
long,not_sweet,not_yellow
long,not_sweet,yellow
not_long,not_sweet,yellow
not_long,not_sweet,yellow
long,not_sweet,not_yellow
not_long,not_sweet,yellow
结果
特征值:[not_long, not_sweet, not_yellow]
预测结果:\'banana\': 0.003, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[not_long, sweet, not_yellow]
预测结果:\'banana\': 0.006999999999999999, \'orange\': 0.0, \'other_fruit\': 0.05625000000000001
水果类别:other_fruit
特征值:[not_long, sweet, yellow]
预测结果:\'banana\': 0.063, \'orange\': 0.15, \'other_fruit\': 0.018750000000000003
水果类别:orange
特征值:[not_long, sweet, yellow]
预测结果:\'banana\': 0.063, \'orange\': 0.15, \'other_fruit\': 0.018750000000000003
水果类别:orange
特征值:[not_long, not_sweet, not_yellow]
预测结果:\'banana\': 0.003, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[long, not_sweet, not_yellow]
预测结果:\'banana\': 0.012, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[long, not_sweet, not_yellow]
预测结果:\'banana\': 0.012, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[long, not_sweet, not_yellow]
预测结果:\'banana\': 0.012, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[long, not_sweet, not_yellow]
预测结果:\'banana\': 0.012, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[long, not_sweet, yellow]
预测结果:\'banana\': 0.108, \'orange\': 0.0, \'other_fruit\': 0.00625
水果类别:banana
特征值:[not_long, not_sweet, yellow]
预测结果:\'banana\': 0.027, \'orange\': 0.15, \'other_fruit\': 0.00625
水果类别:orange
特征值:[not_long, not_sweet, yellow]
预测结果:\'banana\': 0.027, \'orange\': 0.15, \'other_fruit\': 0.00625
水果类别:orange
特征值:[long, not_sweet, not_yellow]
预测结果:\'banana\': 0.012, \'orange\': 0.0, \'other_fruit\': 0.018750000000000003
水果类别:other_fruit
特征值:[not_long, not_sweet, yellow]
预测结果:\'banana\': 0.027, \'orange\': 0.15, \'other_fruit\': 0.00625
水果类别:orange
机器学习强基计划4-3:详解朴素贝叶斯分类原理(附例题+Python实现)
目录
0 写在前面
机器学习强基计划聚焦深度和广度,加深对机器学习模型的理解与应用。“深”在详细推导算法模型背后的数学原理;“广”在分析多个机器学习模型:决策树、支持向量机、贝叶斯与马尔科夫决策、强化学习等。
以上是关于朴素贝叶斯分类器(Python实现+详细源码原理)的主要内容,如果未能解决你的问题,请参考以下文章
《机器学习实战》基于朴素贝叶斯分类算法构建文本分类器的Python实现