映射多个模型
您的工作区中提供的 gap_nested 数据框包含按国家嵌套的 gapminder 数据集。
您将使用这些数据为每个国家建立一个线性模型,用 year 特征来预测 life expectancy(预期寿命)。
注意:术语 feature 与 variable 或 predictor 同义。它指可以用于构建机器学习模型的数据属性。
本练习是课程的一部分
Tidyverse 中的机器学习
练习说明
- 为每个国家建立一个线性模型,使用
year特征来预测life_expectancy。请使用lm()函数完成此操作,并将包含这些模型的新数据框保存为gap_models。 - 从该数据框中提取第一个模型,并将其保存为
algeria_model。 - 使用
summary()查看该模型的信息。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Build a linear model for each country
gap_models <- gap_nested %>%
mutate(model = map(___, ~lm(formula = life_expectancy~year, data = ___)))
# Extract the model for Algeria
algeria_model <- gap_models$model[[___]]
# View the summary for the Algeria model
summary(___)