Predicted values of each fold in K-Fold Cross Vali

2019-06-28 07:26发布

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).

2条回答
forever°为你锁心
2楼-- · 2019-06-28 07:59

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)
查看更多
欢心
3楼-- · 2019-06-28 08:06

I believe you are looking for the cross_val_predict function.

查看更多
登录 后发表回答