모델 계수를 깔끔하게 정리하기
이번 연습 문제에서는 리스트 열 워크플로와 broom 패키지의 tidy() 함수를 활용하여 77개 모델의 계수를 추출하고 탐색합니다.
gap_models 데이터 프레임에는 77개국의 연도에 따른 기대 수명을 예측하는 모델이 포함되어 있다는 점을 기억하세요.
이 연습은 강의의 일부입니다
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()