首页 > 其他 > 详细

决策数题目(是否适合打网球)简单学习-手算

时间:2019-03-23 00:01:47      阅读:180      评论:0      收藏:0      [点我收藏+]

题目:

技术分享图片

 

大致结果手绘图:

技术分享图片

 

详细计算过程:

 一级筛选:

一级筛选
1.天气
from math import*
sum = -(9/14) * log(9/14,2) - (5/14) * log(5/14,2)
a =  5/14*(-(2/5) * log(2/5,2) - (3/5) * log(3/5,2))#晴
b =  4/14*(-1 * log(1,2))#阴
c =  5/14*(-(3/5) * log(3/5,2) - (2/5) * log(2/5,2))#雨
sum1 = a + b + c
print(sum - sum1)
结果
#0.2467498197744391

2.温度
from math import*
sum = -(9/14) * log(9/14,2) - (5/14) * log(5/14,2)
a =  4/14*(-(1/2) * log(1/2,2) - (1/2) * log(1/2,2))#热
b =  6/14*(-(2/3) * log(2/3,2) - (2/3) * log(2/3,2))#温
c =  4/14*(-(3/4) * log(3/4,2) - (1/4) * log(1/4,2))#凉爽
sum1 = a + b + c
print(sum - sum1)
结果
#0.08851363698450365

3.湿度
from math import*
sum = -(9/14) * log(9/14,2) - (5/14) * log(5/14,2)
a =  7/14*(-(3/7) * log(3/7,2) - (4/7) * log(4/7,2))#高
b =  7/14*(-(6/7) * log(6/7,2) - (1/7) * log(1/7,2))#中

sum1 = a + b 
print(sum - sum1)
结果
#0.15183550136234136

4.是否有风
from math import*
sum = -(9/14) * log(9/14,2) - (5/14) * log(5/14,2)
a =  6/14*(-(3/6) * log(3/6,2) - (3/6) * log(3/6,2))#是
b =  8/14*(-(6/8) * log(6/8,2) - (2/8) * log(2/8,2))#否

sum1 = a + b 
print(sum - sum1)
结果
#0.04812703040826927

所以一级筛选选择天气

 

二级筛选:

2.1晴
2.1.1温度
from math import*
sum = -(2/5) * log(2/5,2) - (3/5) * log(3/5,2)
a =  2/5*(-(1/2) * log(1/2,2) - (1/2) * log(1/2,2))#温
#热和凉爽都为0
sum1 = a
print(sum - sum1)
结果
#0.5709505944546686

2.1.2湿度
由于中和高都为0,所以信息增益最大

2.1.3是否有风
from math import*
sum = -(2/5) * log(2/5,2) - (3/5) * log(3/5,2)
a =  2/5*(-(1/2) * log(1/2,2) - (1/2) * log(1/2,2))#是
b =  3/5*(-(1/3) * log(1/3,2) - (2/3) * log(2/3,2))#否
sum1 = a + b
print(sum - sum1)
结果
#0.01997309402197489

所以在二级筛选中晴天时选择湿度

2.2阴————全部适合

2.3雨
2.3.1温度
from math import*
sum = -(2/5) * log(2/5,2) - (3/5) * log(3/5,2)
a =  2/5*(-(1/2) * log(1/2,2) - (1/2) * log(1/2,2))#凉爽
b =  3/5*(-(1/3) * log(1/3,2) - (2/3) * log(2/3,2))#温
#热为0
sum1 = a + b
print(sum - sum1)
结果
#0.01997309402197489

2.3.2湿度
from math import*
sum = -(2/5) * log(2/5,2) - (3/5) * log(3/5,2)
a =  2/5*(-(1/2) * log(1/2,2) - (1/2) * log(1/2,2))#高
b =  3/5*(-(1/3) * log(1/3,2) - (2/3) * log(2/3,2))#中
sum1 = a + b
print(sum - sum1)
结果
#0.01997309402197489

2.3.3是否有风
由于有风和无风都为0,所以信息增益最大

所以在二级筛选中晴天时选择是否有风

 

关于手算有不懂的的地方可以问我~

(争取早点弄出程序,手算费脑子。。。)

决策数题目(是否适合打网球)简单学习-手算

原文:https://www.cnblogs.com/zhying99/p/10582166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!