더 나은 모델 구축하기
앞서 연도(year) 특성을 사용해 기대 수명을 예측하는 단순 모델들을 구축했습니다. 이전 분석에서 일부 모델은 데이터에 잘 맞지 않는다는 것을 확인했습니다.
이번 연습 문제에서는 사용 가능한 모든 특성을 활용하여 각 국가별 다중 회귀 모델을 구축합니다. 가장 적합도가 낮았던 네 국가의 성능을 비교할 수 있도록 해당 국가들의 조정된 \(R^2\) 값을 아래에 제공합니다.
| 국가 | 조정된 \(R^2\) |
|---|---|
| Botswana | -0.0060772 |
| Lesotho | -0.0169851 |
| Zambia | 0.1668999 |
| Zimbabwe | 0.2083979 |
이 연습은 강의의 일부입니다
Tidyverse로 배우는 Machine Learning
연습 안내
- 데이터셋의 모든 특성을 사용하여
life_expectancy를 예측하는 국가별 선형 모델을 구축하세요. - 각 모델의 적합도 통계량을 담은 열(
fit)을 추가하고 데이터 프레임을 간결하게 정리하세요. worst_fit데이터 프레임의 네 국가에 대한 조정된 \(R^2\) 값을fullmodel_perf에서 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Build a linear model for each country using all features
gap_fullmodel <- gap_nested %>%
mutate(model = map(data, ~lm(formula = ___, data = .x)))
fullmodel_perf <- gap_fullmodel %>%
# Extract the fit statistics of each model into data frames
mutate(fit = map(model, ~___(.x))) %>%
# Simplify the fit data frames for each model
unnest(___)
# View the performance for the four countries with the worst fitting four simple models you looked at before
fullmodel_perf %>%
___(country %in% worst_fit$country) %>%
select(country, adj.r.squared)