超參數調校

用 Python 拿下 Kaggle 競賽

Yauhen Babakhin

Kaggle Grandmaster

反覆試驗

模型 驗證 RMSE 公開 LB RMSE 公開 LB 名次
簡單平均 9.986 9.409 1449 / 1500
分組平均 9.978 9.407 1411 / 1500
Gradient Boosting 5.996 4.595 1109 / 1500
加入小時特徵 5.553 4.352 1068 / 1500
加入距離特徵 5.268 4.103 1006 / 1500
... ... ... ...
用 Python 拿下 Kaggle 競賽

反覆試驗

模型 驗證 RMSE 公開 LB RMSE 公開 LB 名次
簡單平均 9.986 9.409 1449 / 1500
分組平均 9.978
Gradient Boosting 5.996 4.595 1109 / 1500
加入小時特徵 5.553
加入距離特徵 5.268 4.103 1006 / 1500
... ... ... ...
用 Python 拿下 Kaggle 競賽

超參數最佳化

 

競賽類型 特徵工程 超參數最佳化
傳統機器學習 +++ +
深度學習 - +++
用 Python 拿下 Kaggle 競賽

Ridge 迴歸

 

最小平方法線性迴歸

$$Loss = \sum_{i=1}^{N}{(y_i - \hat{y}_i)^2} \to \min$$

用 Python 拿下 Kaggle 競賽

Ridge 迴歸

 

最小平方法線性迴歸

$$Loss = \sum_{i=1}^{N}{(y_i - \hat{y}_i)^2} \to \min$$

Ridge 迴歸

$$Loss = \sum_{i=1}^{N}{(y_i - \hat{y}_i)^2 + \alpha\sum_{j=1}^{K}{{w_j}^2}} \to \min$$

用 Python 拿下 Kaggle 競賽

超參數最佳化策略

 

  • 格點搜尋。 選一組預先定義的超參數格點
  • 隨機搜尋。 選定超參數的搜尋空間
  • 貝葉斯最佳化。 選定超參數的搜尋空間

grid search scheme

random search scheme

用 Python 拿下 Kaggle 競賽

格點搜尋

# Possible alpha values
alpha_grid = [0.01, 0.1, 1, 10]

from sklearn.linear_model import Ridge results = {} # For each value in the grid for candidate_alpha in alpha_grid:
# Create a model with a specific alpha value ridge_regression = Ridge(alpha=candidate_alpha)
# Find the validation score for this model
# Save the results for each alpha value results[candidate_alpha] = validation_score
用 Python 拿下 Kaggle 競賽

一起來練習吧!

用 Python 拿下 Kaggle 競賽

Preparing Video For Download...