You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Our R^2 makes odd assumptions, doesn't work with LeaveOneOut #5097
I have wondered for a while if there are cases where the cross validation score should be micro-averaged, i.e. calculate score over output of cross_val_predict rather than averaging scores from each fold's fit.
I did not realize that is what iid is for. I rarely do regression so I didn't know about this behavior of the r2_score. It is quite counter-intuitive :-/
It's not what iid does in my memory, but it might have done so in
prehistory. iid selects between unweighted or sample-size-weighted average
over scores per fold.
I haven't worked with r2 scores before; I might have thought that the
y-mean could be better estimated from the training set.
I did not realize that is what iid is for. I rarely do regression so I
didn't know about this behavior of the r2_score. It is quite
counter-intuitive :-/
—
Reply to this email directly or view it on GitHub #5097 (comment)
.
Should we support the case of metric(y, cross_val_predict(...)) but find a way to document its difference from the mean held-out performance? It requires some change of API (in cross_validate, cross_val_score and BaseSearchCV.cv_results_), because we will no longer be reporting score per-split and the mean across splits.
Would this API change proposal be a candidate for a SLEP? i.e. an option to score all the outputs together rather than average over folds. Or is it too minor of a change for that?
Lol @jnothman agreeing with me for my birthday and I only saw it now!
I think it would warrant a SLEP but honestly I don't know what the solution should be. And I hear more and more people argue against R^2 as a metric :-/
(The broader issue is not R2 so much as metrics which use statistics from
across the test set, rather than being aggregates of individual sample
errors... but I suppose R2 is a particularly hairy case.)
What RidgeCV() is doing is yet another different thing, because it chooses the best parameters of the model based on the CV, which is not what cross_val_score() or GridSearchCVis used for. In that sense, it may be more similar to bootstrapping with OOB samples in RandomForest.
Activity
jnothman commentedon Aug 8, 2015
r2_scoreis returning 0 for any two arrays of shape(1,). According to http://scikit-learn.org/dev/modules/model_evaluation.html#r2-score, this case should rather involve a zero-denominator, but in any case determining the meanyfrom a single sample is blatantly problematic.I have wondered for a while if there are cases where the cross validation score should be micro-averaged, i.e. calculate score over output of
cross_val_predictrather than averaging scores from each fold's fit.agramfort commentedon Aug 8, 2015
amueller commentedon Aug 8, 2015
I did not realize that is what
iidis for. I rarely do regression so I didn't know about this behavior of the r2_score. It is quite counter-intuitive :-/jnothman commentedon Aug 9, 2015
It's not what iid does in my memory, but it might have done so in
prehistory. iid selects between unweighted or sample-size-weighted average
over scores per fold.
I haven't worked with r2 scores before; I might have thought that the
y-mean could be better estimated from the training set.
On 9 August 2015 at 01:32, Andreas Mueller [email protected] wrote:
jnothman commentedon Aug 9, 2015
And iid was introduced by Gaël in a9e73ad, it seems with current semantics.
mblondel commentedon Aug 9, 2015
iidis still inGridSearchCV. I didn't even know there used to beiidin cross_val_score.amueller commentedon Aug 9, 2015
I think r2_score should at least raise a warning with a single sample, if not a ValueError.
And we should probably have a look at what R does here, so we could work around it.
Getting the y-mean from the test data seems slightly odd indeed.
jnothman commentedon Aug 10, 2015
It's not going to be much better with 2 samples!
jnothman commentedon Aug 10, 2015
And getting the y-mean from anything other than the test data makes an
interesting use-case for our scorer API!
amueller commentedon Aug 10, 2015
I agree with both your statements. Relabeling as API bug. We should ask a statistician ^^
1 remaining item
[-]Bug in cross-val-score?[/-][+]Our R^2 makes odd assumptions, doesn't work with LeaveOneOut[/+]hsiaoyi0504 commentedon Apr 22, 2017
Is it already fixed? I am curious about why it works for
RFECVbut doesn't work forcross_val_score(both conditions use leaveOneOut cross validation)jnothman commentedon Jul 5, 2018
I seem to have come to agree with @amueller that we should raise an error with a single sample. See #11435
jnothman commentedon Jul 5, 2018
Should we support the case of
metric(y, cross_val_predict(...))but find a way to document its difference from the mean held-out performance? It requires some change of API (incross_validate,cross_val_scoreandBaseSearchCV.cv_results_), because we will no longer be reporting score per-split and the mean across splits.adrinjalali commentedon Dec 13, 2018
Would this API change proposal be a candidate for a SLEP? i.e. an option to score all the outputs together rather than average over folds. Or is it too minor of a change for that?
amueller commentedon Dec 13, 2018
Lol @jnothman agreeing with me for my birthday and I only saw it now!
I think it would warrant a SLEP but honestly I don't know what the solution should be. And I hear more and more people argue against R^2 as a metric :-/
adrinjalali commentedon Dec 13, 2018
I think the API proposal is independent of whether we want to keep/recommend R^2 or not, the user can use the same API/solution for other scorers.
amueller commentedon Dec 13, 2018
It's much less pressing if we move away from R^2, though.
jnothman commentedon Dec 17, 2018
amueller commentedon Dec 17, 2018
@jnothman I think we're on the same page.
MLopez-Ibanez commentedon Oct 6, 2021
By the way, the special case of LOOCV leads to some wrong assumptions: https://machinelearningmastery.com/loocv-for-evaluating-machine-learning-algorithms/
When implementing LOOCV manually, the author uses
accuracy_score()on they_predandy_truecollected from all test folds.However, when using
cross_val_score(), the accuracy scorer is applied to each test folds individually. The author (and surely many users) does not notice the difference because the result is the same foraccuracy_score, however, it would not be the same for most scoring metrics specially those for regression. Perhaps this page should warn about this pitfall: https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.LeaveOneOut.htmlWhat
RidgeCV()is doing is yet another different thing, because it chooses the best parameters of the model based on the CV, which is not whatcross_val_score()orGridSearchCVis used for. In that sense, it may be more similar to bootstrapping with OOB samples inRandomForest.