-->

Predicted values of each fold in K-Fold Cross Vali

2019-06-28 07:22发布

问题:

I have performed 10-fold cross validation on a dataset that I have using python sklearn,

result = cross_val_score(best_svr, X, y, cv=10, scoring='r2') print(result.mean())

I have been able to get the mean value of the r2 score as the final result. I want to know if there is a way to print out the predicted values for each fold( in this case 10 sets of values).

回答1:

I believe you are looking for the cross_val_predict function.



回答2:

To print the predictions for each fold,

for k in range(2,10):
    result = cross_val_score(best_svr, X, y, cv=k, scoring='r2')
    print(k, result.mean())
    y_pred = cross_val_predict(best_svr, X, y, cv=k)
    print(y_pred)