【问题标题】:Implementing a decision tree using h2o使用 h2o 实现决策树
【发布时间】:2018-11-17 07:33:39
【问题描述】:

我正在尝试使用 h2o 训练决策树模型。我知道 h2o 中没有特定的决策树库。但是,h2o 实现了随机森林 H2ORandomForestEstimator。我们可以通过调整随机森林的某些输入参数在 h2o 中实现决策树吗?因为我们可以在 scikit 模块(一个流行的机器学习 Python 库)中做到这一点

参考链接: Why is Random Forest with a single tree much better than a Decision Tree classifier?

在 scikit 中,代码看起来像这样

RandomForestClassifier(n_estimators=1, max_features=None, bootstrap=False)

我们在 h2o 中有与此代码等效的代码吗?

【问题讨论】:

    标签: python machine-learning scikit-learn decision-tree h2o


    【解决方案1】:

    您可以使用 H2O 的随机森林 (H2ORandomForestEstimator),设置 ntrees=1 使其仅构建一棵树,将 mtries 设置为您在数据集中拥有的特征(即列)数和 sample_rate =1。将 mtries 设置为数据集中的特征数意味着算法将从决策树中每个级别的所有特征中随机抽样。

    这里有更多关于mtries:http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/algo-params/mtries.html的信息

    【讨论】:

    • 如果我想在我的 RandomForestEstimator 中使用 categorical_encoding = 'enum' 怎么办?由于 H2O 的分类编码,我不知道模型将用于预测的最终特征数量。在这种情况下如何设置 mtries,以便模型按照您的建议使用所有功能?
    • 这不能回答我的问题。我问:由于categorical_encoding='enum' 我不知道用于训练的特征数量。因此我无法按照您的建议设置mtries - 参数。在这种情况下如何设置mtries
    • mtries 设置为数据集中原始特征的数量。请阅读categorical_encoding='enum' 的链接描述以了解原因(即编码使数据集保持原样并提供从字符串到整数的映射)。
    • 如果我将 mtries 设置为预测变量的数量 (21),我会收到一条错误消息,指出 mtries 可以在区间 [1,16[ 但不是 21。
    【解决方案2】:

    补充 Lauren 的回答:基于 PUBDEV-4324 - Expose Decision Tree as a stand-alone algo in H2O,DRF 和 GBM 都可以完成这项工作,而 GBM 稍微容易一些:

    titanic_1tree = h2o.gbm(x = predictors, y = response, 
                            training_frame = titanicHex,
                            ntrees = 1, min_rows = 1, sample_rate = 1,            
                            col_sample_rate = 1,
                            max_depth = 5,
                            seed = 1)
    

    在 Titanic 数据集上创建一个最多 5 个深度分割 (max_depth = 5) 的决策树(可在此处获得:https://s3.amazonaws.com/h2o-public-test-data/smalldata/gbm_test/titanic.csv

    从版本 3.22.0.1 (Xia) 开始,可以从 H2O 模型中提取树结构:

    titanicH2oTree = h2o.getModelTree(model = titanic_1tree, tree_number = 1)
    

    【讨论】:

      猜你喜欢
      • 2019-11-19
      • 1970-01-01
      • 2019-02-03
      • 2016-09-02
      • 1970-01-01
      • 2022-07-19
      • 2011-03-25
      • 2011-02-27
      • 2011-03-22
      相关资源
      最近更新 更多