朴素贝叶斯分类器精选
朴素贝叶斯分类器
Naive Bayesian Classifier
C语言实现
信息电气工程学院
计算本1102班
20112212465
马 振 磊贝叶斯公式
通过贝叶斯公式,我们可以的知在属性F1-Fn成立的情况下,该样本属于分类C的概率。
而概率越大,说明样本属于分类C的可能性越大。
若某样本可以分为2种分类A,B。
要比较P(A | ) 与 P(B | )的大小只需比较,P(A)P( A) ,与P(B)P( B) 。
因为两式分母一致。
而P(A)P( A)可以采用缩放为P(A)P(F1|A)P(F2|A).......(Fn|A)
因此,在分类时,只需比较每个属性在分类下的概率累乘,再乘该分类的概率即可。
分类属性outlook属性temperature属性humidity属性windnosunnyhothighweaknosunnyhothighstrongyesovercasthothighweakyesrainmildhighweakyesraincoolnormalweaknoraincoolnormalstrongyesovercastcoolnormalstrongnosunnymildhighweakyessunnycoolnormalweakyesrainmildnormalweakyessunnymildnormalstrongyesovercastmildhighstrongyesovercasthotnormalweaknorainmildhighstrong
以上是根据天气的4种属性,某人外出活动的记录。
若要根据以上信息判断
(Outlook = sunny,Temprature = cool,Humidity = high,Wind = strong)
所属分类。
P(yes| sunny ,cool ,high ,strong )=P(yes)P(sunny|yes)P(cool |yes)P(high|yes)P(strong|yes)/K
P(no| sunny ,cool ,high ,strong )=P(no)P(sunny|no)P(cool |no)P(high|no)P(strong|no)/K
K为缩放因子,我们只需要知道两个概率哪个大,所以可以忽略K。
P(yes)=9/14 P(no)=5/14
P(sunny|yes)=2/9 P(cool|yes)=1/3 P(high|yes)=1/3 P(strong|yes)=1/3
P(sunny|no)=3/5 P(cool|no)=1/5 P(high|no)=4/5 P(strong|no)=3/5
P(yes| sunny ,cool ,high ,strong)=9/14*2/9*1/3*1/3*1/3=0.00529
P(no| sunny ,cool ,high ,strong )=5/14*3/5*1/5*4/5*3/5=0.20571
No的概率大,所以该样本实例属于no分类。
2.数据结构及代码实现
1.属性及分类
我们限定分类器的属性不大于9个,每个属性拥有不大于9个值。于是,我们考虑采用一个9 X 9的表格存储属性及其值。
属性1值1值2值3值4值5值6值7值8值9属性2值1值2值3值4值5值6值7值8值9属性3值1值2值3值4值5值6值7值8值9属性4值1值2值3值4值5值6值7值8值9属性5值1值2值3值4值5值6值7值8值9属性6值1值2值3值4值5值6值7值8值9属性7值1值2值3值4值5值6值7值8值9属性8值1值2值3值4值5值6值7值8值9属性9值1值2
本文发布于:2024-01-27 22:53:05,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063671883131.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |