使用 H2O 進行自動化機器學習

R 的超參數調校

Dr. Shirin Elsinghorst

Senior Data Scientist

自動化機器學習(AutoML)

  • 自動調校演算法,不只超參數

 

  • AutoML 讓模型調校與最佳化更快速又容易

 

  • AutoML 只需要一個資料集目標變數,以及訓練用的時間或模型數上限
R 的超參數調校

H2O 的 AutoML

AutoML 會比較:

  • 一般化線性模型(GLM)
  • (分散式)隨機森林(DRF)
  • 極端隨機樹(XRT)
  • XGBoost(Extreme Gradient Boosting)
  • Gradient Boosting 機器(GBM)
  • 深度學習(全連接多層類神經網路)
  • 疊代集成(所有模型與各家族最佳)
R 的超參數調校

GBM 超參數

  • histogram_type
  • ntrees
  • max_depth
  • min_rows
  • learn_rate
  • sample_rate
  • col_sample_rate
  • col_sample_rate_per_tree
  • min_split_improvement

Deep Learning 超參數

  • epochs
  • adaptivate_rate
  • activation
  • rho
  • epsilon
  • input_dropout_ratio
  • hidden
  • hidden_dropout_ratios
R 的超參數調校
# Using h2o.automl function
automl_model <- h2o.automl(x = x, y = y,
                           training_frame = train,
                           validation_frame = valid,
                           max_runtime_secs = 60,
                           sort_metric = "logloss",
                           seed = 42)
  • 會回傳依所選指標(此處為「logloss」)排序的所有模型排行榜
Slot "leader":
Model Details:
==============

H2OMultinomialModel: gbm
Model Summary: 
 number_of_trees number_of_internal_trees model_size_in_bytes min_depth
             189                      567               65728         1
 max_depth mean_depth min_leaves max_leaves mean_leaves
         5    2.96649          2          6     4.20988
R 的超參數調校

檢視 AutoML 排行榜

lb <- automl_model@leaderboard
                                    model_id mean_per_class_error
1  GBM_grid_0_AutoML_20181029_144443_model_6           0.01851852
2 GBM_grid_0_AutoML_20181029_144443_model_30           0.02777778
3 GBM_grid_0_AutoML_20181029_144443_model_18           0.02777778
4  GBM_grid_0_AutoML_20181029_144443_model_9           0.03703704
  • 預設排行榜以 5 折交叉驗證計算。

https://docs.h2o.ai/h2o/latest-stable/h2o-docs/automl.html

R 的超參數調校

從 AutoML 排行榜擷取模型

# List all models by model id
model_ids <- as.data.frame(lb)$model_id
 [1] "GBM_grid_0_AutoML_20181029_144443_model_6"       
 [3] "GBM_grid_0_AutoML_20181029_144443_model_18"         
[19] "XRT_0_AutoML_20181029_144443"
[20] "DRF_0_AutoML_20181029_144443"            
[24] "DeepLearning_0_AutoML_20181029_144443"                        
[41] "StackedEnsemble_BestOfFamily_0_AutoML_20181029_144443" 
[42] "StackedEnsemble_AllModels_0_AutoML_20181029_144443" 
# Get the best model
aml_leader <- automl_model@leader
  • aml_leader 仍是一般的 H2O 模型物件,你可以照常使用。
R 的超參數調校

準備好進入最後一輪練習!

R 的超參數調校

Preparing Video For Download...