使用 H2O 的自动化机器学习

R 中的超参数调优

Dr. Shirin Elsinghorst

Senior Data Scientist

自动化机器学习(AutoML)

  • 除了超参数外,还可进行算法的自动调优

 

  • AutoML 使模型调优与优化更快、更易

 

  • AutoML 只需提供数据集、目标变量,以及时间或模型数量上限
R 中的超参数调优

H2O 中的 AutoML

AutoML 比较:

  • 广义线性模型(GLM)
  • 极端随机树(XRT)
  • Extreme Gradient Boosting(XGBoost)
  • 梯度提升(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

深度学习超参数

  • epochs
  • adaptivate_rate
  • activation
  • rho
  • epsilon
  • input_dropout_ratio
  • hidden
  • hidden_dropout_ratios
R 中的超参数调优
# 使用 h2o.automl 函数
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 排行榜提取模型

# 按模型 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" 
# 获取最优模型
aml_leader <- automl_model@leader
  • aml_leader 仍是常规的 H2O 模型 对象,可按常规模型使用。
R 中的超参数调优

准备开始最后一轮练习!

R 中的超参数调优

Preparing Video For Download...