开始使用免费开始使用

为突发情况做准备

在 Brett 连续 13 周记录自己的位置期间,他从未在周末去过办公室。因此,联合概率 P(office and weekend) = 0。

请探索这会如何影响模型对 Brett 将来周末去上班概率的预测。此外,您还可以看到,使用拉普拉斯校正会为此类意外情况保留一个很小的可能性。

模型 locmodel 和数据框 weekend_afternoon 已为您提供。naivebayes 包也已预加载。

本练习是课程的一部分

R 中的监督学习:分类

查看课程

练习说明

  • 使用 locmodelpredict() 函数在周末下午情境下输出预测概率。记得设置 type 参数。
  • 新建一个将拉普拉斯平滑参数设为 1 的朴素贝叶斯模型。可在调用 naive_bayes() 时设置 laplace 参数。将其保存为 locmodel2
  • 使用 predict() 在新模型上进行预测,比较新的预测概率。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Observe the predicted probabilities for a weekend afternoon


# Build a new model using the Laplace correction
locmodel2 <- ___

# Observe the new predicted probabilities for a weekend afternoon
编辑并运行代码