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

喜你入骨 提交于 2019-12-10 18:26:34

问题


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)


来源:https://stackoverflow.com/questions/51718734/predicted-values-of-each-fold-in-k-fold-cross-validation-in-sklearn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!