使用分类输入进行建模
在本练习中,您将对 flowers 数据拟合线性模型,用 Time 和 Intensity 来预测 Flowers。
您在上一个练习中创建的模型公式 fmla 仍然可用,模型矩阵 mmat 也同样可用。
本练习是课程的一部分
R 中的监督学习:回归
练习说明
- 使用
fmla和lm训练一个线性模型,从Intensity和Time预测Flowers。将模型赋值给变量flower_model。 - 使用
summary()回顾mmat的结构。 - 使用
summary()检查flower_model。这些变量是否与您在mmat中看到的一致? - 使用
flower_model预测花朵数量。将预测结果作为列predictions添加到flowers中。 - 填空绘制预测值与真实花朵数量的散点图(预测值在 x 轴)。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# flowers is available
str(flowers)
# fmla is available
fmla
# Fit a model to predict Flowers from Intensity and Time : flower_model
flower_model <- ___
# Use summary on mmat to remind yourself of its structure
___
# Use summary to examine flower_model
___
# Predict the number of flowers on each plant
flowers$predictions <- ___
# Plot predictions vs actual flowers (predictions on x-axis)
ggplot(___, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(color = "blue")