始める無料で始める

eta のチューニング

ここからは、他の XGBoost ハイパーパラメータの本格的なチューニングと、それがモデル性能に与える影響を確認していきます。まずは学習率として知られる "eta" を調整します。

XGBoost の学習率は 0 から 1 の範囲のパラメータで、"eta" を大きくすると特徴量の重みに対するペナルティが強くなり、より強力な正則化がかかります。

この演習はコースの一部です

XGBoost で学ぶ極限の勾配ブースティング

コースを見る

演習の手順

  • 次の "eta" の値を格納するリスト eta_vals を作成します: 0.001, 0.01, 0.1
  • for ループで eta_vals を反復します。
  • 各反復で、params"eta" キーに curr_val を代入します。その後、早期終了(5 ラウンド)付きの 3 分割交差検証、ブースティングラウンド数 10、評価指標 "rmse"seed123 にして実行します。出力は DataFrame になるようにしてください。
  • 最終ラウンドの RMSE を best_rmse リストに追加します。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

# Create your housing DMatrix: housing_dmatrix
housing_dmatrix = xgb.DMatrix(data=X, label=y)

# Create the parameter dictionary for each tree (boosting round)
params = {"objective":"reg:squarederror", "max_depth":3}

# Create list of eta values and empty list to store final round rmse per xgboost model
____ = [____, ____, ____]
best_rmse = []

# Systematically vary the eta 
for curr_val in ____:

    params["___"] = curr_val
    
    # Perform cross-validation: cv_results
    cv_results = ____
    
    
    
    # Append the final round rmse to best_rmse
    ____.____(____["____"].tail().values[-1])

# Print the resultant DataFrame
print(pd.DataFrame(list(zip(eta_vals, best_rmse)), columns=["eta","best_rmse"]))
コードを編集して実行