对单个树估计器进行权重运算以从梯度提升分类估计器预测值

时间:2018-06-20 08:31:53

标签: python-3.x scikit-learn classification random-forest decision-tree

gbm0 = GradientBoostingClassifier(n_estimators=500, random_state=42)
%time modelfit(gbm0, X_train, y_train)

##model fit is a fucntion i wrote to create a report on gbm classifier

preds = np.stack([t.predict(X_valid) for t in gbm0.estimators_])

给出错误

  ----> 1 preds = np.stack([t.predict(X_valid) for t in gbm0.estimators_])

 AttributeError: 'numpy.ndarray' object has no attribute 'predict'

我如何访问单个树的预测方法以查看预测?

1 个答案:

答案 0 :(得分:0)

数组estimators_的形状为(n_estimators, 1),用于二进制分类。因此,您可以通过重塑来纠正错误:

preds = np.stack([t.predict(X_valid) for t in gbm0.estimators_.reshape(-1)])