최적 모델 구축 및 평가
교차 검증(cross-validation)을 통해 gapminder의 모든 특성을 활용하여 life_expectancy를 예측하는 최적 모델을 선정했습니다. 모델을 선택했으니, 이제 별도로 보관해 둔 독립 데이터셋(testing_data)을 사용하여 새로운 데이터에 대한 모델 성능을 추정할 차례입니다.
모든 training_data로 모델을 구축하고, testing_data로 평가를 진행합니다.
이 연습은 강의의 일부입니다
Tidyverse로 배우는 Machine Learning
연습 안내
ranger()를 사용하여 모든 학습 데이터로 최적 모델(mtry = 4)을 구축하고, 결과를best_model에 할당하세요.testing_data에서life_expectancy열을 추출하여test_actual에 할당하세요.best_model을 사용해testing데이터의life_expectancy를 예측하고, 결과를test_predicted에 할당하세요.test_actual과test_predicted벡터를 사용하여 MAE를 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Build the model using all training data and the best performing parameter
best_model <- ranger(formula = ___, data = ___,
mtry = ___, num.trees = 100, seed = 42)
# Prepare the test_actual vector
test_actual <- testing_data$___
# Predict life_expectancy for the testing_data
test_predicted <- predict(___, ___)$predictions
# Calculate the test MAE
mae(___, ___)