在gridsearchcv期间打印不合时宜的预测

时间:2019-06-17 07:24:21

标签: python scikit-learn random-forest cross-validation gridsearchcv

在拟合gridsearchcv(针对随机森林)的过程中,如何打印出每个折叠(训练/测试)集的真实值与预测值(数组)?

代码示例:

parameters = {
        'bootstrap': [True, False],
        'max_depth': [20,25,30],
        'min_samples_leaf': [1,2,3],
        'n_estimators': [450,500,550],
        'n_jobs': [-1]}
inner_cv = KFold(n_splits=3, shuffle=False, random_state=None)
reg = GridSearchCV(estimator=RandomForestRegressor(),
                   param_grid=parameters, cv=inner_cv)
reg.fit(X_train, y_train)

另一篇文章建议了这一点,但我觉得应该在试穿时返回:

y_pred = cross_val_predict(reg, X_train, y_train, cv=inner_cv)

* Predicted values of each fold in K-Fold Cross Validation in sklearn

0 个答案:

没有答案