开始使用免费开始使用

一个试探性的模型

给您一个数据集,包含在不同距离下两个物体之间引力的测量值。任务是建立一个简单模型,根据给定距离预测该引力。起初,您打算先用简单线性回归。数据由 120 对 distanceforce 组成,已加载为 newton

本练习是课程的一部分

R 中的特征工程

查看课程

练习说明

  • 使用基础 R 的线性模型函数为 newton 数据建立线性模型,并将其赋值给 lr_force
  • 通过将预测值与原始 newton 数据绑定,创建新的数据框 df
  • 使用 ggplot() 生成 forcedistance 的散点图。
  • 在散点图上添加基于拟合值的回归直线。

交互式实操练习

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

# Build a linear model for the newton the data and assign it to lr_force
lr_force <- ___(force ~ distance, data = ___)

# Create a new data frame by binding the prediction values to the original data
df <- newton %>% ___(lr_pred = predict(lr_force))

# Generate a scatterplot of force vs. distance
df %>%
  ggplot(aes(x = distance, y = force)) +
  geom____() +
# Add a regression line with the fitted values
  geom_line(aes(y = ___), color = "blue", lwd = .75) +
  ggtitle("Linear regression of force vs. distance") +
  theme_classic()
编辑并运行代码