开始使用免费开始使用

整理模型的系数

在本练习中,您将结合列表列(list column)工作流与 broom 包中的 tidy() 函数,提取并探索您构建的 77 个模型的系数。

请记住,数据框 gap_models 包含的是针对 77 个国家,以 year 预测 life expectancy 的模型。

本练习是课程的一部分

Tidyverse 中的机器学习

查看课程

练习说明

  • 使用 tidy(),为 gap_models 数据框追加一列(coef),其中包含每个模型的系数统计,并将结果保存为 model_coef_nested
  • 使用 unnest() 将该数据框展开,提取这些系数。
  • 通过绘制直方图来探索 77 个模型中 year 特征的系数估计值分布。

交互式实操练习

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

# Extract the coefficient statistics of each model into nested data frames
model_coef_nested <- gap_models %>% 
    mutate(coef = map(model, ~___(.x)))
    
# Simplify the coef data frames for each model    
model_coef <- model_coef_nested %>%
    unnest(___)

# Plot a histogram of the coefficient estimates for year         
model_coef %>% 
  filter(term == "___") %>% 
  ggplot(aes(x = ___)) +
  geom_histogram()
编辑并运行代码