开始使用免费开始使用

使用分类输入进行建模

在本练习中,您将对 flowers 数据拟合线性模型,用 TimeIntensity 来预测 Flowers

您在上一个练习中创建的模型公式 fmla 仍然可用,模型矩阵 mmat 也同样可用。

本练习是课程的一部分

R 中的监督学习:回归

查看课程

练习说明

  • 使用 fmlalm 训练一个线性模型,从 IntensityTime 预测 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") 
编辑并运行代码