[英]Call SKLearn's cross_val_score and cross_val_predict at the same time?
I am running a nested-cross validation with cross_val_score
by passing a GridSearchCV
object to it.我通过将
GridSearchCV
对象传递给cross_val_score
来运行嵌套交叉验证。 Then I follow up with cross_val_predict
to get model predictions for graphing.然后我跟进
cross_val_predict
以获得用于绘图的模型预测。 Like this:像这样:
gs = GridSearchCV(mymodel, myparams)
score = cross_val_score(gridsearch, X_train, y_train)
prediction = cross_val_predict(gs, X_train, y_train)
This seems computationally redundant;这在计算上似乎是多余的; is there a way to get the cross-validated predictions from
cross_val_score
, or do I need to manually iterate through the folds of a CV object to do this in one step?有没有办法从
cross_val_score
获得交叉验证的预测,或者我是否需要手动遍历 CV 对象的折叠以一步完成?
From what I am seeing in the documentation it appears that cross_val_score
and cross_val_predict
obtain their values by different processes and it is not recommended for the two to be combined.从我在文档中看到的情况来看,
cross_val_score
和cross_val_predict
似乎是通过不同的过程获取它们的值,不建议将两者结合使用。
https://scikit-learn.org/stable/modules/cross_validation.html#obtaining-predictions-by-cross-validation https://scikit-learn.org/stable/modules/cross_validation.html#obtaining-predictions-by-cross-validation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.