開始使用免費開始

整理模型的係數

在這個練習中,你會結合清單欄位的工作流程,以及 broom 套件的 tidy() 函式,來擷取並探索你建立的 77 個模型的係數。

請記得,gap_models 資料框包含了 77 個國家的模型,用 year 預測 life expectancy

本練習屬於課程

Tidyverse 的 Machine Learning

檢視課程

練習說明

  • 使用 tidy() 將每個模型的係數統計附加成一個新欄位(coef)到 gap_models 資料框,並另存為 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()
編輯並執行程式碼