如何在GBRT估计器(Python)中找到X映射到的叶节点的索引?

2024-10-05 14:29:49 发布

您现在位置:Python中文网/ 问答频道 /正文

在sklearn中实现的随机林中有apply(X)函数-GBRT有等价的吗?你知道吗

编辑时间:

for estimator in gbrt.estimators_:
    estimator.tree_.apply(X)

提供:

File "<pyshell#29>", line 2, in <module>
estimator.tree_.apply(Z)
AttributeError: 'numpy.ndarray' object has no attribute 'tree_'

Tags: 函数intree编辑for时间sklearnfile
1条回答
网友
1楼 · 发布于 2024-10-05 14:29:49

您可以使用每个applyestimator.tree_方法:

for estimator in gbrt.estimators_:
    estimator.tree_.apply(X)

如果要进行多类分类,则每个阶段的每个类将有一棵树,因此需要执行以下操作:

for step in gbrt.estimators_:
    for class_estimator in step:
        class_estimator.tree_.apply(X)

相关问题 更多 >