【问题标题】:H2O DistributedRandomForest all tree predictionsH2O DistributedRandomForest 所有树预测
【发布时间】:2019-07-20 03:02:45
【问题描述】:

我使用 Python 的 H2O(版本 3.22.1.3),我想知道是否可以像 scikit-learn 的 RandomForestRegressor.estimators_ 方法一样观察随机森林中每棵树的预测。我尝试使用 h2o.predict_leaf_node_assignment(),但它带来了每棵树的预测路径或(假设)基于其进行预测的叶节点的 id。在上一个版本中,H2O 添加了 Tree 类,但不幸的是,它没有任何 predict() 方法。尽管我可以访问任何随机森林树中的任何节点,但我使用树最近实现的 API(即使任何正确的 API)实现树预测功能仍然非常缓慢。所以,我的问题是:

(a) 我可以在本地获取树预测,如果可以,那么如何?

(b) 如果否,H2O 开发人员是否计划在未来的版本中实现此功能?

任何回复将不胜感激。

更新:谢谢乔,您的回复。至于现在(在直接实现该功能之前),这是我能想到的唯一解决方法,它会生成树预测。

# Suppose we have random forest model called drf with ntrees=70 and want to make predictions on df_valid
# After executing the code below, we get a dataframe tree_predictions with ntrees (in our case 70) columns, where i-th column corresponds to the predictions of i-th tree, and the same number of rows as df_valid.
# Extract the trees to create prediction intervals
# Number of trees
ntrees = 70

from h2o.tree import H2OTree
# Extract all the tree of drf, create the list of prediction trees
list_of_trees = [H2OTree(model = drf, tree_number = t, tree_class = None) for t in range(ntrees)]

# leaf_nodes contains the node_id's of tree leaves with predictions
leaf_nodes = drf.predict_leaf_node_assignment(df_valid, type='Node_ID').as_data_frame()

# tree_predictions is the dataframe with predictions for all the 70 trees
tree_predictions = pd.DataFrame(columns=['T'+str(t+1) for t in range(ntrees)])
for t in range(ntrees):
    tr = list_of_trees[t]
    node_ids = np.array(tr.node_ids)
    treePred = lambda n: tr.predictions[np.where(node_ids==n)[0][0]] 
    tree_predictions['T'+str(t+1)] = leaf_nodes['T'+str(t+1)].apply(treePred)enter code here

【问题讨论】:

    标签: python tree random-forest h2o


    【解决方案1】:

    现在的答案是否定的。我们创建了一个在 Tree API 中实现新功能的问题。您可以在此处跟踪进度:https://0xdata.atlassian.net/browse/PUBDEV-6322

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-26
      • 2018-07-16
      • 2019-07-20
      • 2023-03-27
      • 2019-03-04
      • 2018-08-30
      • 1970-01-01
      • 2017-06-24
      相关资源
      最近更新 更多