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'
我如何访问单个树的预测方法以查看预测?
答案 0 :(得分:0)
数组estimators_
的形状为(n_estimators, 1)
,用于二进制分类。因此,您可以通过重塑来纠正错误:
preds = np.stack([t.predict(X_valid) for t in gbm0.estimators_.reshape(-1)])