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

如何在GBRT估计器(Python)中找到叶节点X映射到的索引?,python,machine-learning,scikit-learn,decision-tree,Python,Machine Learning,Scikit Learn,Decision Tree,在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

在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_'
文件“”,第2行,在
估计树应用(Z)
AttributeError:“numpy.ndarray”对象没有属性“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)

我收到一条执行此操作的错误消息…gbrt是否具有此属性?是。错在哪里?啊。抱歉,gbrt.estimators是一个由形状
(n\u个估计器,n\u个类)
组成的numpy数组。