Tidy up the coefficients of your models
In this exercise you will leverage the list column workflow along with the tidy()
function from broom
to extract and explore the coefficients for the 77 models you built.
Remember the gap_models
data frame contains a model predicting life expectancy by year for 77 countries.
Cet exercice fait partie du cours
Machine Learning in the Tidyverse
Instructions
- Use
tidy()
to append a column (coef
) containing coefficient statistics for each model to thegap_models
data frame and save it asmodel_coef_nested
. - Simplify this data frame using
unnest()
to extract these coefficients in your data frame. - Explore the coefficient estimates for the year feature across your 77 models by plotting a histogram of their values.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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()