使用 h2o 实现决策树

Implementing a decision tree using h2o

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

中做到这一点

参考 link :

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

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

我们在 h2o 中是否有此代码的等效项?

您可以使用 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

补充 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 数据集(可在此处获得:https://s3.amazonaws.com/h2o-public-test-data/smalldata/gbm_test/titanic.csv

上创建最多 5 个分裂深度(max_depth = 5)的决策树

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

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