15. 计算题 使用朴素贝叶斯方法,给出当天气晴朗、车辆破损时是否外出? # weather(天气状况) car(车辆状况) out(是否外出) 1 Sunny working go-out 2 Rainy broken go-out 3 Sunny working go-out 4 Sunny working go-out 5 Sunny working go-out 6 Rainy broken stay-home 7 Rainy broken stay-home 8 Sunny working stay-home 9 Sunny broken stay-home 10 Rainy broken stay-home Sunny broken ??
时间: 2024-04-01 17:31:01 浏览: 66
使用贝叶斯方法预测天气状况
根据朴素贝叶斯算法,我们需要分别计算天气状况、车辆状况、是否外出这三个属性的先验概率和条件概率,并利用贝叶斯公式计算后验概率,最终选择后验概率大的结果作为预测结果。
首先,计算天气状况、车辆状况、是否外出这三个属性的先验概率:
- 天气状况(Sunny/Rainy)的先验概率:$P(Sunny)=\frac{5}{10}=0.5$,$P(Rainy)=\frac{5}{10}=0.5$
- 车辆状况(working/broken)的先验概率:$P(working)=\frac{6}{10}=0.6$,$P(broken)=\frac{4}{10}=0.4$
- 是否外出(go-out/stay-home)的先验概率:$P(go-out)=\frac{5}{10}=0.5$,$P(stay-home)=\frac{5}{10}=0.5$
接下来,计算每个属性下不同取值的条件概率:
- 天气状况(Sunny/Rainy)下是否外出(go-out/stay-home)的条件概率:
$$P(go-out|Sunny)=\frac{4}{5}=0.8, \quad P(stay-home|Sunny)=\frac{1}{5}=0.2$$
$$P(go-out|Rainy)=\frac{1}{5}=0.2, \quad P(stay-home|Rainy)=\frac{4}{5}=0.8$$
- 车辆状况(working/broken)下是否外出(go-out/stay-home)的条件概率:
$$P(go-out|working)=\frac{5}{6}=0.833, \quad P(stay-home|working)=\frac{1}{6}=0.167$$
$$P(go-out|broken)=\frac{0}{4}=0, \quad P(stay-home|broken)=\frac{4}{4}=1$$
根据贝叶斯公式,我们可以计算在天气状况为“Sunny”,车辆状况为“broken”时,是否外出的后验概率:
$$\begin{aligned}P(go-out|Sunny,broken)&=\frac{P(Sunny|go-out)P(broken|go-out)P(go-out)}{P(Sunny)P(broken)}\\&=\frac{P(Sunny|go-out)P(broken|go-out)P(go-out)}{P(Sunny)P(broken|Sunny)P(Sunny)+P(Rainy)P(broken|Rainy)P(Rainy)}\\&=\frac{0.8*0*0.5}{0.5*0.4*0.5+0.5*0*0.5}\\&=0\end{aligned}$$
$$\begin{aligned}P(stay-home|Sunny,broken)&=\frac{P(Sunny|stay-home)P(broken|stay-home)P(stay-home)}{P(Sunny)P(broken)}\\&=\frac{P(Sunny|stay-home)P(broken|stay-home)P(stay-home)}{P(Sunny)P(broken|Sunny)P(Sunny)+P(Rainy)P(broken|Rainy)P(Rainy)}\\&=\frac{0*1*0.5}{0.5*0.4*0.5+0.5*0*0.5}\\&=0\end{aligned}$$
因此,当天气状况为“Sunny”,车辆状况为“broken”时,预测结果为“stay-home”。
阅读全文