始める無料で始める

最良モデルの構築と評価

交差検証により、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_actualtest_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(___, ___)
コードを編集して実行