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"、seedを123にして実行します。出力は 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"]))