首页 > 解决方案 > 错误:AttributeError:“GridSearchCV”对象没有属性“staged_predict”

问题描述

这是估算器的声明:

from sklearn.model_selection import GridSearchCV

param_grid = {'learning_rate': [0.1],
              'max_depth': [4],
              'min_samples_leaf': [3],
              'max_features': [1.0]
              }
est = GridSearchCV(ensemble.GradientBoostingRegressor(n_estimators=100),
                   param_grid, n_jobs=4, refit=True)

est.fit(X_train, y_train)

best_params = est.best_params_

%%time
est = ensemble.GradientBoostingRegressor(n_estimators=500).fit(X_train, y_train)

运行之后,当我运行以下代码时出现错误

Iterations = 2000
# compute test set deviance
test_score = np.zeros((Iterations,), dtype=np.float64)

for i, y_pred in enumerate(est.staged_predict(X_test)):
    test_score[i] = est.loss_(y_test, y_pred)

AttributeError                            Traceback (most recent call last)
<ipython-input-188-bbd634856a9f> in <module>
      9 test_score = np.zeros((Iterations,), dtype=np.float64)
     10 
---> 11 for i, y_pred in enumerate(est.staged_predict(X_test)):
     12     test_score[i] = est.loss_(y_test, y_pred)
     13 

AttributeError: 'GridSearchCV' object has no attribute 'staged_predict'

任何人都可以就可能出现的问题提供一些见解。我很确定 staged_predict 仍然包含在 scikit learn 的 Model_Selection 模块中。

标签: pythonpandasscikit-learngridsearchcv

解决方案


推荐阅读