一个试探性的模型
给您一个数据集,包含在不同距离下两个物体之间引力的测量值。任务是建立一个简单模型,根据给定距离预测该引力。起初,您打算先用简单线性回归。数据由 120 对 distance 和 force 组成,已加载为 newton。
本练习是课程的一部分
R 中的特征工程
练习说明
- 使用基础
R的线性模型函数为newton数据建立线性模型,并将其赋值给lr_force。 - 通过将预测值与原始
newton数据绑定,创建新的数据框df。 - 使用
ggplot()生成force与distance的散点图。 - 在散点图上添加基于拟合值的回归直线。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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()