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
Add "scoring" argument to estimator's score method #28995
I want to enable non-accuracy metrics to estimator.score, and ultimately deprecate the default values of accuracy and r2. I would call it scoring though it's a bit redundant but consistent.
That would allow us to get rid of the default scoring methods, which are objectively bad and misleading, and it would require the minimum amount of code changes for anyone.
Describe your proposed solution
Replace
est.score(X, y)
with
est.score(X, y, scoring="accuracy")
or rather
est.score(X, y, scoring="recall_macro")
(or r2 for regression).
Describe alternatives you've considered, if relevant
Keep current status, which is bad (both accuracy and r2 are bad)
Remove scoring method.
I can't think of any other alternatives tbh.
Additional context
I think in theory this requires a slep, as it's changing shared API, right?
Well there is already a separate module for importing metrics..
This score function uses default metric to predict based on ur estimator.
Can't we just make a bridge between the scoring parameter u want and the metrics sklearn module, such that it refers to the metric from sklearn module.
Besides this, there are lot of non accuracy metrics....which one should we focus upon
I agree that current score behavior is at best useless, at worst bad.
But IMO, the question is a bit broader: does scikit-learn want to have more syntactic sugar or not?
If yes, then adding the possibility of choosing the metric to the score method should be the way to go. If not, removing the score method, which will be a breaking change, will ease the codebase and maintenance.
Can't we just make a bridge between the scoring parameter u want and the metrics sklearn module, such that it refers to the metric from sklearn module.
The scorers are the bridge to sklearn.metric. The scorers add additional metadata on top of sklearn.metrics that tells the estimator what it needs to compute for a specific metric. For example:
But IMO, the question is a bit broader: does scikit-learn want to have more syntactic sugar or not?
I'm okay with adding a scorer argument est.score because it makes it easier to switch between metrics. I think there is a API gap between using est.score to a scorer or a metric in sklearn.metric. For example, to use the ROC scorer:
# User needs to know about `get_scorer`fromsklearn.metricsimportget_scorerroc_auc_scorer=get_scorer("roc_auc")
roc_auc_scorer(est, X_test, y_test)
Or using the metrics directly:
fromsklearn.metricsimportroc_auc_score# User needs to know that `roc_auc_score` requires `y_score`:y_decision=est.decision_function(X_test)
roc_auc_score(y_test, y_decision)
# Of if estimator only has `predict_proba`:roc_auc_score(y, clf.predict_proba(X)[:, 1])
With this proposal, we can write est.score(X_test, y_test, scoring="roc_auc").
I would be in favor of deprecating default scorers.
A few related points:
Do we let users do something line estimator.set_scorer("roc_auc") and use it in *SearchCV? I rather not. Prefer to always require users to specify scorer when calling score.
We can start by deprecating scoring=None in all search methods/classes.
Can users pass anything that check_scoring accepts to estimator.score? I guess yes? While deprecating _Passthrough I'd say.
I think it needs a SLEP because it is going to change deeply the API.
Regarding the default scorers, considering the difficulties to select the right metric for each use case, then not having a default might be better.
Do we let users do something line estimator.set_scorer("roc_auc") and use it in *SearchCV
To me this is an extension of the API. We don't need to settle on this at first. Having the scoring parameter everywhere and behaving consistently would already be good.
Can users pass anything that check_scoring accepts to estimator.score
I would say yes but it means that we need to properly define what is the scorer API. For instance, there already this difference between metric scorer and curve scorer (that does not exist yet but it probably should).
Why call the argument scoring? For me something like scorer sounds better, maybe just because it isn't a verb :-/
est.score(X, y, scorer="accuracy")
est.score(X, y, scorer="recall_macro")
I am -1 on set_scorer.
I think providing a default metric as part of an estimator is useful for users. A bit like setting something like the number of trees in a random forest. While ten (I think the current default) is rarely the right value, I think it is useful that step 1 of using RandomForestClassifier isn't "think about a (random) value for each of its constructor arguments so that it starts working".
Same with the metric you use to evaluate your setup. You almost always want to think about it and make a deliberate choice, but the fact that there is a default to get you started is a good thing imho.
I agree on not adding set_scorer. Also agree with the rest of what @adrinjalali suggested.
I would say yes but it means that we need to properly define what is the scorer API. For instance, there already this difference between metric scorer and curve scorer (that does not exist yet but it probably should).
Can you elaborate on that? I think I'm not familiar with the proposal.
@betatim I suggested scoring because that's the argument in cross_validate and GridSearchCV and they are probably that just because we had scorer before with a different API and we had to do a deprecation cycle?
While ten (I think the current default) is rarely the right value, I
It's 100, we fixed that quite a while ago :)
I think the default parameters and the default metric have indeed similar properties, though I'd say the consequences of the choice of metric are even worse.
The problem on both accounts is that people don't do the second step of actually thinking about it.
There's some hyper-parameters that have a huge impact, like kernel in SVC, but I think not tuning hypers is rarely as bad as using accuracy in an imbalanced classification problem (which is all classification problems).
Also, knowing reasonable defaults for all the model is not really feasible; but if you don't know how to pick at least a reasonable metric for your task, you probably shouldn't build a model yet.
I proposed two changes, adding they keyword arg, and removing the default. Just adding the keyword arg would at least smooth over the path from using accuracy to using something more relevant.
I think we're hurting people by not forcing people to think about their performance metrics. Those metrics have real life consequences and our defaults make no sense, and have nothing to do with the real life usecase at hand for the user.
We should have a much better documentation page on how to choose the metric for that purpose, and then we should force people to choose themselves.
Reacted by Hleb Levitski, Pragyan Tiwari , Andreas Mueller and Christian Lorentzen
That depends on your definition of "help". The only thing I personally need is 1 (the ability to change the default). 2 will take much longer to make a decision on.
I probably won't have the bandwidth to participate in the full discussion, I'm starting a new job tomorrow. I'll respond briefly to your points above though.
I had not heard about it before this slep. Having a default that is not well-known is pretty strange.
That is not a good argument.
I strongly disagree. I think it is a critical argument for a good user interface. I would like some of the more long term core devs like @GaelVaroquaux@adrinjalali@jnothman to weigh in on this. I think it's a good idea for scikit-learn to encourage best practices. I don't think it's a good idea for scikit-learn to try to establish new practices that are not well-supported by the literature. If you want this to be the new standard in the ML community, I'd recommend writing a paper about it, going to the ML evaluation and benchmarking workshops, and discussing the ideas there.
I want scikit-learn to do the right thing but even more so, I want its behavior to be unsurprising.
The ranking of models by R^2 and by mean squared error is the same. R^2 is dimensionless, best value 1. I guess this is the main reason why many prefer it over squared error.
The right thing to do would be to fit a dummy regressor on the training set and use this one as baseline instead of the mean of the test set target/response. This would then be a real skill score. But the score method does not have access to the training data
I agree, giving the score access to the training data would be the right thing to do. I would do that before trying to establish a metric that requires this to be meaningful. I disagree that people prefer the R^2 in machine learning. I went to a whole talk by Max Kuhn about why people should stop using it.
It's not applicable to decision_function.
There is no need for that. It is applicable to predict, it prefers predict_proba. This combination was one of the main reasons I propose this score.
I don't understand the argument. Yes it can use predict but that throws away most of the information so you'd get a much better score if you wrap it into a CalibratedClassifierCV and get predict_proba, or even if you do some stupid ad-hoc normalization. Either of these seem strange.
I am 100% against any score that uses a fixed threshold,
I don't have a very strong opinion on that point. I can see both sides.
some variant of AP or ROC AUC
This contradicts your statement above, requesting additivity overs samples.
Yes, there's trade-offs. I think additivity over samples is good. I still think these are good candidates.
I am 100% on the opposite site. Please refer to literature about why or read our own user guide: which scoring function should I use. Note that many professionals prefer probabilistic predictions, a few examples:
I'm pretty sad to see the current introduction tbh. This seems less helpful than what was there before. I totally agree that probabilistic predictions are extremely helpful. One of the bigger changes I made in sklearn was allowing grid-search to work with probabilistic scoring functions, not just predictions. I'm just saying that I might lean towards something that can directly produce predictions for the default. If we only do probabilistic models, this is somewhat less of an issue (but that has other issues, see below). There is a bit of an issue with pure ranking metrics like AUC that you can have a score of 1 even if accuracy is 0, which is quite strange. Probabilistic metrics don't have that issue (since they are proper scoring rules), but will make evaluating non-probabilistic classifiers quite strange.
There are several aspects of decisions here, and for some I can see going both ways, i.e. going non-additive and going uncertainty based. But trying to establish a new norm I am convinced is a bad idea. The last aspect is prioritizing probabilistic predictions. I am hesitant to do that as a default and I want do elaborate on that.
One of the consequence of your proposed change is that non-probabilistic classifiers will become second-rate classifiers automatically. This goes back to the support of decision_function. If you do a grid-search with Logistic Regression and LinearSVC, Logistic Regression will always win with the new default, because it's uncertainty estimates are preserved in the metric, but not in LinearSVC. To me, that is a bad thing. We're hiding a decision we made about how we want to evaluate. The only way to not do that is to calibrate all non-probabilistic classifiers by default, which will also be surprising.
The same issue would happen with log-loss, which is probably the loss I would pick if we favor a probabilistic viewpoint.
Reacted by Joel Nothman, Adrin Jalali and Gael Varoquaux
scikit-learn is about making it easy to do the right thing, especially for the busy, overloaded, non ML expert
scikit-learn isn't a good library for changing what the world is doing. We don't want to be trail blazers/establishing new methods or campaigning for new norms
I think there is some tension between these two points but it is possible to full fill both at the same time. For example, doing the "right thing" is a combination of what is technically correct and what is pragmatically correct. Often the two are the same, but sometimes they are not. I think this current discussion is a case where they are not the same. There is no value for scoring= that ticks all the boxes of requirements.
By making it easy to do the right thing we can change what the norm is. Maybe train_test_split is a good example. People use it because it is easier to use it than to write the few lines of code that the busy, overloaded, non ML expert thinks are needed to do the job. By using it they also avoid a lot of pitfalls that they don't (yet) know about and maybe if train_test_split wasn't so prominent and easy to use there would be more people who evaluate on the data they trained on. So we do improve the world and make what people do more correct. But, it is important that there is nothing controversial about splitting your data - it is a well established norm.
Splitting your data is also a place where you can see that we don't make it easy enough to do the right thing. Having a training and testing set is good, but really you need a training, testing and validation dataset. Our tooling doesn't make it quite as easy to implement this, but luckily it is not too difficult for the busy, overloaded, non ML expert to explain to their colleagues why this is a good thing to do and how to do it. Despite all this, data leakage remains a common problem.
For me this little story is useful to judge the level of understanding, effort and available brain power in - what I imagine to be a common scikit-learn user - the busy, overloaded, non ML expert.
For me, right now, this means that adding the scoring argument is a good thing to do. We start a conversation with our users and we give experts a way to do their thing. What value to choose for it is less clear to me, it seems there is no "no brainer" option. This means I'd move ahead with introducing the argument and defaulting to the current behaviour. While not a great solution it has the advantage that my assumed user persona will not get shouted at by someone in their organisation/paper reviewer/etc for doing something "weird" (that they can't fully explain). I think it is better that people use an imperfect scikit-learn and have an effect on the real world and real people with it, than that they use something else because scikit-learn is considered "too weird".
Maybe all this is biased by my experience of wanting to use scikit-learn as a young graduate student and having to frequently justify why I wasn't using TMVA which was the standard and had the support of the ML experts in my field of research. My feeling that scikit-learn was probably more correct was just a feeling. The more differences there are between the accepted and the alternative approach the more time I had to spend understanding what the difference really was and which one made sense. All the while being reminded that my job was to do physics research, not become a ML researcher.
I had not heard about it before this slep. Having a default that is not well-known is pretty strange.
That is not a good argument.
I strongly disagree. I think it is a critical argument for a good user interface. [...] If you want this to be the new standard in the ML community, I'd recommend writing a paper about it, going to the ML evaluation and benchmarking workshops, and discussing the ideas there.
First, arguing that you not knowing much about it results in rejecting the hypothesis (that Brier score is a good default) is the informal fallacy of argumentum ad ignorantiam.
Second, better than me writing a paper, let's see what Brier wrote in his 1950 paper:
(for ML people: forecast=predict, verification=scoring, scale of goodness=scoring metric)
INTRODUCTION
Verification of weather forecasts has been a controversial subject for more than a half century. There are a number of reasons why this problem has been so perplexing to meteorologists and others but one of the most important difficulties seems to be in reaching an agreement on the specification of a scale of goodness for weather forecasts. Numerous systems have been proposed but one of the greatest arguments raised against forecast verification is that forecasts which may be the “best” according to the accepted system of arbitrary scores may not be the most useful forecasts. In attempting to resolve this difficulty the forecaster may often find himself in the position of choosing to ignore the verification system or to let it, do the forecasting for him by “hedging” or “playing the system.” This may lead the forecaster to forecast something other than what he thinks will occur, for it is often easier to analyze the effect of different possible forecasts on the verification score than it is to analyze the weather situation. It is generally agreed that this state of affairs is unsatisfactory, as one essential criterion for satisfactory verification is that the verification scheme should influence the forecaster in no undesirable way. Unfortunately, the criterion is difficult, if not impossible to satisfy, although some schemes will be much worse than others in this respect.
It is the purpose of this paper to discuss one situation where it appears to be possible to devise a verification scheme that cannot influence the forecaster in any undesirable way. This is the case when forecasts are expressed in terms of probability statements. The advantages of expressing the degree of assumed reliability of a forecast numerically have been discussed previously [l, 2, 3, 4] so that the purpose here will not be to emphasize the enhanced usefulness of such forecasts but rather to point out how some aspects of the verification problem are simplified or solved.
Please be also aware that G. Brier and J. Thompson already used the confusion matrix (they called it contingency table) and analysed different cost-loss ratios for optimal decision making.
The last aspect is prioritizing probabilistic predictions. I am hesitant to do that as a default and I want do elaborate on that. [...] If you do a grid-search with Logistic Regression and LinearSVC, Logistic Regression will always win with the new default [...]
Please note that the current default score, i.e. accuracy, does the opposite: LinearSVC will most likely win.
Gneiting wrote in his 2008 editorial:
[..]Weather forecasting has traditionally been viewed as a deterministic exercise, drawing on highly sophisticated numerical models of the atmosphere. The advent of operational ensemble prediction systems in the 1990s marked a radical change (Palmer, 2002; Gneiting and Raftery, 2005), culminating in a recent National Academies report that calls for a reorientation of environmental prediction efforts towards probabilistic forecasting (National Research Council, 2006).
Hi there, I want to shed some theoretical light on this discussion, as I've seen some seminal papers on the topic mentioned, and I think that it in useful to explain how the connect to machine learning. I'll be brief because I rushing on research papers for ICML, one of them on a quite related topic :).
I know well the theory around risks and proper scoring rules. One of my former students (Alex Perez-Lebel) did a PhD on related topics, and ended up bridging the risk as measured by a proper scoring rule with a post-threshold error control (in the sens of cost-sensitive learning, or decision theory with utility function).
The core argument in favor of proper scoring rules is that, at their minimum, we obtain P(y|X), but this theory tells us nothing about what happens far from the optimum, which is a common case. And when we are not at the optimum (a case studied in Section II.3 of Alex's thesis), it is needed to consider the application risk and compare models based on this.
There are multiple reasons why one may not be at the optimum, one is ill-specified models (very common), another may be using a model that does not give proper probabilities, which are very common in machine learning (SVC, RidgeClassifier, RandomForest and ExtraTrees, NearestNeighbors with a small number of neighbors). In such settings the right thing is to use the application risk, which often boils down to putting weights on the errors on class 0 and class 1. The AUC gives good control on such risk. Also, the Tuned Threshold classifiers enable the user to set the optimal threshold for these downstream risks.
Indeed, often the user is not going to use not the probability, but a thresholded version of it. The proper scoring rules do not control these well at all (unless they are at the optimal point).
Finally, I want to stress that what I am writing is in nowhere in contradiction with the seminal work of Brier and related thinkers. As explained very well in the introductory chapter of the thesis of Alex Perez mentioned above, the seminal work argues that selecting the forecast (the historical work was written in the context of forecasting) that minimizes a proper scoring rule enables separating the design of a forecast from its use by striving to approach P(y|X). However, in modern machine learning practice, the model is often created for a specific use, and not as a general forecast. Hence the tradeoff is different, and the recommendation is to evaluate on this use.
All this to say that what the theory tell thus is not that proper scoring rules are the best solution for all application. Rather, it tells us that "it's complicated", as often. This argues for keeping mind the common practice and well understood concept as default.
Thanks for the link to the thesis, very interesting to read, indeed.
All this to say that what the theory tell thus is not that proper scoring rules are the best solution for all application. Rather, it tells us that "it's complicated", as often. This argues for keeping mind the common practice and well understood concept as default.
I think W. Brier already wrote it to the point. In my words: We don't know anything about the operating conditions of the model application, the cost/utility matrix, the use case, the kind of decision, what is best in that situation. Our first recommendation should be (and actually is) to adapt to the use case.
A default can't do that, and the only sensible default score that does not allow to "play the system", as Brier calls it, is a proper scoring rule, ideally one that also works for deterministic/hard predictions.
First, arguing that you not knowing much about it results in rejecting the hypothesis (that Brier score is a good default) is the informal fallacy of argumentum ad ignorantiam.
It depends. If the criterion is solely theoretical (or practical) properties of the scoring rule, I would agree. My point is that this should not be the sole basis for making API decisions, and in that case I think it's an extremely relevant argument.
Second, better than me writing a paper, let's see what Brier wrote in his 1950 paper:
(for ML people: forecast=predict, verification=scoring, scale of goodness=scoring metric
Clearly him writing the paper was not enough since the metric is not widely used in classification. It doesn't really matter how good the argument is if people are unaware in the community.
Please note that the current default score, i.e. accuracy, does the opposite: LinearSVC will most likely win.
Only if it's better for the deterministic case, which is the most common application of models. Also, the advantage is not systematic in the sense that it's not an artifact of the metric not being able to capture critical aspects of the model.
First, arguing that you not knowing much about it results in rejecting the hypothesis (that Brier score is a good default) is the informal fallacy of argumentum ad ignorantiam.
It depends. If the criterion is solely theoretical (or practical) properties of the scoring rule, I would agree. My point is that this should not be the sole basis for making API decisions, and in that case I think it's an extremely relevant argument.
Relevant or not. An argumentum ad ignorantiam can‘t be reasoned against. It is considered an invalid argument.
See below for degree of recognition in different communities.
Second, better than me writing a paper, let's see what Brier wrote in his 1950 paper:
(for ML people: forecast=predict, verification=scoring, scale of goodness=scoring metric
Clearly him writing the paper was not enough since the metric is not widely used in classification. It doesn't really matter how good the argument is if people are unaware in the community.
That depends highly on the community. The medical literature knows it (see Steyerberg‘s book „Clinical Prediction Models“ or the recent The Lancet article, they also know the „R2“ variant, sometimes called scaled Brier score), the meteorologists and atmospheric scientists know it (Wilks‘ book „Statistical Methods in Atmospheric Sciences", as well as the book "Forecast Verification" by Jolliffe and Stephenson), the statistics and forecasting literature does, … Do data scientists really intend to reinvent every wheel?
Please note that the current default score, i.e. accuracy, does the opposite: LinearSVC will most likely win.
Only if it's better for the deterministic case, which is the most common application of models. Also, the advantage is not systematic in the sense that it's not an artifact of the metric not being able to capture critical aspects of the model.
I argue against this statement. Deterministic models are often trained on a score approximating accuracy. Good for them. Probabilistic models don’t know about thresholds while training. Afterwards a threshold of 50% is imposed on them and that is the main culprit of our default scorer (not the metric per se). Therefore, probabilistic models have a systematic disadvantage by scikit-learn‘s default scoring.
Stated otherwise: The main problem is the default threshold of 50% in classifier.predict. One could conclude to remove predict for probabilistic classifiers. But the API disruption would be much larger than a change of default scorer.
A bit more fun with Brier score for binary classification: Remember that the optimal probability threshold is the cost loss ratio. If we assume a uniform distribution of the cost loss ratio over all use cases in the universe, then the expectation of the cost-weighted misclassification error (just the integral over it) turns out to be the Brier score.
Another point for the theoretical discussion about how to select the best probabilistic classifier in terms of strictly proper scoring rules: it can be beneficial to first select the highest refinement/most discriminative hyper-parameters (e.g. tune hparam on ROC AUC) first and then calibrate the predictions rather that selecting the hparams on the strictly proper scoring rule directly: https://arxiv.org/abs/2501.19195.
I found this a bit counterintuitive and so I figured that people not familiar with this work might find it interesting.
In the course of this discussion, I have learnt a few new things.
The following finding I wanted to share with you, in particular with the remaining fan club of accuracy. The final evaluation here is accuracy, but the scoring of LogisticRegressionCV differs, lr_acc uses accuracy, lr_lls uses log loss (Note that accuracy was the default scoring in LogisticRegressionCV until today, see #33333):
Very small p-value => hypothesis of equal (mean) accuracy can be rejected.
Conclusion: Even when you are finally interested in accuracy, using log loss or the estimators loss function might achieve better results than scikit-learn default scores.
Activity
prgyn8 commentedon May 12, 2024
Well there is already a separate module for importing metrics..
This score function uses default metric to predict based on ur estimator.
Can't we just make a bridge between the scoring parameter u want and the metrics sklearn module, such that it refers to the metric from sklearn module.
Besides this, there are lot of non accuracy metrics....which one should we focus upon
glevv commentedon May 12, 2024
I agree that current
scorebehavior is at best useless, at worst bad.But IMO, the question is a bit broader: does scikit-learn want to have more syntactic sugar or not?
If yes, then adding the possibility of choosing the metric to the
scoremethod should be the way to go. If not, removing thescoremethod, which will be a breaking change, will ease the codebase and maintenance.thomasjpfan commentedon May 12, 2024
The scorers are the bridge to
sklearn.metric. The scorers add additional metadata on top ofsklearn.metricsthat tells the estimator what it needs to compute for a specific metric. For example:scikit-learn/sklearn/metrics/_scorer.py
Lines 810 to 814 in 5e5cc34
I'm okay with adding a
scorerargumentest.scorebecause it makes it easier to switch between metrics. I think there is a API gap between usingest.scoreto a scorer or a metric insklearn.metric. For example, to use the ROC scorer:Or using the metrics directly:
With this proposal, we can write
est.score(X_test, y_test, scoring="roc_auc").adrinjalali commentedon May 13, 2024
I would be in favor of deprecating default scorers.
A few related points:
estimator.set_scorer("roc_auc")and use it in*SearchCV? I rather not. Prefer to always require users to specify scorer when callingscore.scoring=Nonein all search methods/classes.check_scoringaccepts toestimator.score? I guess yes? While deprecating_PassthroughI'd say.This probably does need a SLEP.
glemaitre commentedon May 13, 2024
I think it needs a SLEP because it is going to change deeply the API.
Regarding the default scorers, considering the difficulties to select the right metric for each use case, then not having a default might be better.
To me this is an extension of the API. We don't need to settle on this at first. Having the
scoringparameter everywhere and behaving consistently would already be good.I would say yes but it means that we need to properly define what is the scorer API. For instance, there already this difference between metric scorer and curve scorer (that does not exist yet but it probably should).
betatim commentedon May 13, 2024
Why call the argument
scoring? For me something likescorersounds better, maybe just because it isn't a verb :-/I am -1 on
set_scorer.I think providing a default metric as part of an estimator is useful for users. A bit like setting something like the number of trees in a random forest. While ten (I think the current default) is rarely the right value, I think it is useful that step 1 of using
RandomForestClassifierisn't "think about a (random) value for each of its constructor arguments so that it starts working".Same with the metric you use to evaluate your setup. You almost always want to think about it and make a deliberate choice, but the fact that there is a default to get you started is a good thing imho.
amueller commentedon May 13, 2024
I agree on not adding
set_scorer. Also agree with the rest of what @adrinjalali suggested.Can you elaborate on that? I think I'm not familiar with the proposal.
@betatim I suggested
scoringbecause that's the argument incross_validateandGridSearchCVand they are probably that just because we hadscorerbefore with a different API and we had to do a deprecation cycle?It's 100, we fixed that quite a while ago :)
I think the default parameters and the default metric have indeed similar properties, though I'd say the consequences of the choice of metric are even worse.
The problem on both accounts is that people don't do the second step of actually thinking about it.
There's some hyper-parameters that have a huge impact, like kernel in SVC, but I think not tuning hypers is rarely as bad as using accuracy in an imbalanced classification problem (which is all classification problems).
Also, knowing reasonable defaults for all the model is not really feasible; but if you don't know how to pick at least a reasonable metric for your task, you probably shouldn't build a model yet.
I proposed two changes, adding they keyword arg, and removing the default. Just adding the keyword arg would at least smooth over the path from using accuracy to using something more relevant.
prgyn8 commentedon May 14, 2024
What would be the default value of scorer?..
scorer = None ???
If you compare it to GridSearchCV etc.
They usually come with 'accuracy' as default scoring technique.
Moreover, scorer value would vary a lot in order to run multiple benchmark models.
My question is would you conclude to put None as default value?
adrinjalali commentedon May 14, 2024
I think we're hurting people by not forcing people to think about their performance metrics. Those metrics have real life consequences and our defaults make no sense, and have nothing to do with the real life usecase at hand for the user.
We should have a much better documentation page on how to choose the metric for that purpose, and then we should force people to choose themselves.
26 remaining items
adamjstewart commentedon Jan 24, 2026
That depends on your definition of "help". The only thing I personally need is 1 (the ability to change the default). 2 will take much longer to make a decision on.
amueller commentedon Jan 25, 2026
I probably won't have the bandwidth to participate in the full discussion, I'm starting a new job tomorrow. I'll respond briefly to your points above though.
I strongly disagree. I think it is a critical argument for a good user interface. I would like some of the more long term core devs like @GaelVaroquaux @adrinjalali @jnothman to weigh in on this. I think it's a good idea for scikit-learn to encourage best practices. I don't think it's a good idea for scikit-learn to try to establish new practices that are not well-supported by the literature. If you want this to be the new standard in the ML community, I'd recommend writing a paper about it, going to the ML evaluation and benchmarking workshops, and discussing the ideas there.
I want scikit-learn to do the right thing but even more so, I want its behavior to be unsurprising.
I agree, giving the score access to the training data would be the right thing to do. I would do that before trying to establish a metric that requires this to be meaningful. I disagree that people prefer the R^2 in machine learning. I went to a whole talk by Max Kuhn about why people should stop using it.
I don't understand the argument. Yes it can use
predictbut that throws away most of the information so you'd get a much better score if you wrap it into a CalibratedClassifierCV and get predict_proba, or even if you do some stupid ad-hoc normalization. Either of these seem strange.I don't have a very strong opinion on that point. I can see both sides.
Yes, there's trade-offs. I think additivity over samples is good. I still think these are good candidates.
I'm pretty sad to see the current introduction tbh. This seems less helpful than what was there before. I totally agree that probabilistic predictions are extremely helpful. One of the bigger changes I made in sklearn was allowing grid-search to work with probabilistic scoring functions, not just predictions. I'm just saying that I might lean towards something that can directly produce predictions for the default. If we only do probabilistic models, this is somewhat less of an issue (but that has other issues, see below). There is a bit of an issue with pure ranking metrics like AUC that you can have a score of 1 even if accuracy is 0, which is quite strange. Probabilistic metrics don't have that issue (since they are proper scoring rules), but will make evaluating non-probabilistic classifiers quite strange.
There are several aspects of decisions here, and for some I can see going both ways, i.e. going non-additive and going uncertainty based. But trying to establish a new norm I am convinced is a bad idea. The last aspect is prioritizing probabilistic predictions. I am hesitant to do that as a default and I want do elaborate on that.
One of the consequence of your proposed change is that non-probabilistic classifiers will become second-rate classifiers automatically. This goes back to the support of
decision_function. If you do a grid-search with Logistic Regression and LinearSVC, Logistic Regression will always win with the new default, because it's uncertainty estimates are preserved in the metric, but not in LinearSVC. To me, that is a bad thing. We're hiding a decision we made about how we want to evaluate. The only way to not do that is to calibrate all non-probabilistic classifiers by default, which will also be surprising.The same issue would happen with log-loss, which is probably the loss I would pick if we favor a probabilistic viewpoint.
betatim commentedon Jan 26, 2026
Some of my thoughts.
I think there is some tension between these two points but it is possible to full fill both at the same time. For example, doing the "right thing" is a combination of what is technically correct and what is pragmatically correct. Often the two are the same, but sometimes they are not. I think this current discussion is a case where they are not the same. There is no value for
scoring=that ticks all the boxes of requirements.By making it easy to do the right thing we can change what the norm is. Maybe
train_test_splitis a good example. People use it because it is easier to use it than to write the few lines of code that the busy, overloaded, non ML expert thinks are needed to do the job. By using it they also avoid a lot of pitfalls that they don't (yet) know about and maybe iftrain_test_splitwasn't so prominent and easy to use there would be more people who evaluate on the data they trained on. So we do improve the world and make what people do more correct. But, it is important that there is nothing controversial about splitting your data - it is a well established norm.Splitting your data is also a place where you can see that we don't make it easy enough to do the right thing. Having a training and testing set is good, but really you need a training, testing and validation dataset. Our tooling doesn't make it quite as easy to implement this, but luckily it is not too difficult for the busy, overloaded, non ML expert to explain to their colleagues why this is a good thing to do and how to do it. Despite all this, data leakage remains a common problem.
For me this little story is useful to judge the level of understanding, effort and available brain power in - what I imagine to be a common scikit-learn user - the busy, overloaded, non ML expert.
For me, right now, this means that adding the
scoringargument is a good thing to do. We start a conversation with our users and we give experts a way to do their thing. What value to choose for it is less clear to me, it seems there is no "no brainer" option. This means I'd move ahead with introducing the argument and defaulting to the current behaviour. While not a great solution it has the advantage that my assumed user persona will not get shouted at by someone in their organisation/paper reviewer/etc for doing something "weird" (that they can't fully explain). I think it is better that people use an imperfect scikit-learn and have an effect on the real world and real people with it, than that they use something else because scikit-learn is considered "too weird".Maybe all this is biased by my experience of wanting to use scikit-learn as a young graduate student and having to frequently justify why I wasn't using TMVA which was the standard and had the support of the ML experts in my field of research. My feeling that scikit-learn was probably more correct was just a feeling. The more differences there are between the accepted and the alternative approach the more time I had to spend understanding what the difference really was and which one made sense. All the while being reminded that my job was to do physics research, not become a ML researcher.
lorentzenchr commentedon Jan 26, 2026
First, arguing that you not knowing much about it results in rejecting the hypothesis (that Brier score is a good default) is the informal fallacy of argumentum ad ignorantiam.
Second, better than me writing a paper, let's see what Brier wrote in his 1950 paper:
(for ML people: forecast=predict, verification=scoring, scale of goodness=scoring metric)
Please be also aware that G. Brier and J. Thompson already used the confusion matrix (they called it contingency table) and analysed different cost-loss ratios for optimal decision making.
Please note that the current default score, i.e. accuracy, does the opposite: LinearSVC will most likely win.
Gneiting wrote in his 2008 editorial:
GaelVaroquaux commentedon Jan 28, 2026
Hi there, I want to shed some theoretical light on this discussion, as I've seen some seminal papers on the topic mentioned, and I think that it in useful to explain how the connect to machine learning. I'll be brief because I rushing on research papers for ICML, one of them on a quite related topic :).
I know well the theory around risks and proper scoring rules. One of my former students (Alex Perez-Lebel) did a PhD on related topics, and ended up bridging the risk as measured by a proper scoring rule with a post-threshold error control (in the sens of cost-sensitive learning, or decision theory with utility function).
His manuscript is extremely clear thesis, and worth looking for people interested: https://theses.hal.science/tel-05115306/.
The introductory chapter provides a nuanced summary of the classical arguments, and Section II.3 is where he bridges probabilistic control and post-decision control, showing that the connections are remarkably subtle.
The core argument in favor of proper scoring rules is that, at their minimum, we obtain P(y|X), but this theory tells us nothing about what happens far from the optimum, which is a common case. And when we are not at the optimum (a case studied in Section II.3 of Alex's thesis), it is needed to consider the application risk and compare models based on this.
There are multiple reasons why one may not be at the optimum, one is ill-specified models (very common), another may be using a model that does not give proper probabilities, which are very common in machine learning (SVC, RidgeClassifier, RandomForest and ExtraTrees, NearestNeighbors with a small number of neighbors). In such settings the right thing is to use the application risk, which often boils down to putting weights on the errors on class 0 and class 1. The AUC gives good control on such risk. Also, the Tuned Threshold classifiers enable the user to set the optimal threshold for these downstream risks.
Indeed, often the user is not going to use not the probability, but a thresholded version of it. The proper scoring rules do not control these well at all (unless they are at the optimal point).
Finally, I want to stress that what I am writing is in nowhere in contradiction with the seminal work of Brier and related thinkers. As explained very well in the introductory chapter of the thesis of Alex Perez mentioned above, the seminal work argues that selecting the forecast (the historical work was written in the context of forecasting) that minimizes a proper scoring rule enables separating the design of a forecast from its use by striving to approach P(y|X). However, in modern machine learning practice, the model is often created for a specific use, and not as a general forecast. Hence the tradeoff is different, and the recommendation is to evaluate on this use.
All this to say that what the theory tell thus is not that proper scoring rules are the best solution for all application. Rather, it tells us that "it's complicated", as often. This argues for keeping mind the common practice and well understood concept as default.
lorentzenchr commentedon Jan 28, 2026
Thanks for the link to the thesis, very interesting to read, indeed.
I think W. Brier already wrote it to the point. In my words: We don't know anything about the operating conditions of the model application, the cost/utility matrix, the use case, the kind of decision, what is best in that situation. Our first recommendation should be (and actually is) to adapt to the use case.
A default can't do that, and the only sensible default score that does not allow to "play the system", as Brier calls it, is a proper scoring rule, ideally one that also works for deterministic/hard predictions.
amueller commentedon Feb 2, 2026
It depends. If the criterion is solely theoretical (or practical) properties of the scoring rule, I would agree. My point is that this should not be the sole basis for making API decisions, and in that case I think it's an extremely relevant argument.
Clearly him writing the paper was not enough since the metric is not widely used in classification. It doesn't really matter how good the argument is if people are unaware in the community.
Only if it's better for the deterministic case, which is the most common application of models. Also, the advantage is not systematic in the sense that it's not an artifact of the metric not being able to capture critical aspects of the model.
lorentzenchr commentedon Feb 2, 2026
Relevant or not. An argumentum ad ignorantiam can‘t be reasoned against. It is considered an invalid argument.
See below for degree of recognition in different communities.
That depends highly on the community. The medical literature knows it (see Steyerberg‘s book „Clinical Prediction Models“ or the recent The Lancet article, they also know the „R2“ variant, sometimes called scaled Brier score), the meteorologists and atmospheric scientists know it (Wilks‘ book „Statistical Methods in Atmospheric Sciences", as well as the book "Forecast Verification" by Jolliffe and Stephenson), the statistics and forecasting literature does, … Do data scientists really intend to reinvent every wheel?
I argue against this statement. Deterministic models are often trained on a score approximating accuracy. Good for them. Probabilistic models don’t know about thresholds while training. Afterwards a threshold of 50% is imposed on them and that is the main culprit of our default scorer (not the metric per se). Therefore, probabilistic models have a systematic disadvantage by scikit-learn‘s default scoring.
Stated otherwise: The main problem is the default threshold of 50% in
classifier.predict. One could conclude to removepredictfor probabilistic classifiers. But the API disruption would be much larger than a change of default scorer.lorentzenchr commentedon Feb 5, 2026
A bit more fun with Brier score for binary classification: Remember that the optimal probability threshold is the cost loss ratio. If we assume a uniform distribution of the cost loss ratio over all use cases in the universe, then the expectation of the cost-weighted misclassification error (just the integral over it) turns out to be the Brier score.
ogrisel commentedon Feb 23, 2026
Another point for the theoretical discussion about how to select the best probabilistic classifier in terms of strictly proper scoring rules: it can be beneficial to first select the highest refinement/most discriminative hyper-parameters (e.g. tune hparam on ROC AUC) first and then calibrate the predictions rather that selecting the hparams on the strictly proper scoring rule directly: https://arxiv.org/abs/2501.19195.
I found this a bit counterintuitive and so I figured that people not familiar with this work might find it interesting.
lorentzenchr commentedon Mar 16, 2026
In the course of this discussion, I have learnt a few new things.
The following finding I wanted to share with you, in particular with the remaining fan club of accuracy. The final evaluation here is accuracy, but the scoring of LogisticRegressionCV differs, lr_acc uses accuracy, lr_lls uses log loss (Note that accuracy was the default scoring in LogisticRegressionCV until today, see #33333):
OK, maybe that was by chance:
Still not satisfied?
Very small p-value => hypothesis of equal (mean) accuracy can be rejected.
Conclusion: Even when you are finally interested in accuracy, using log loss or the estimators loss function might achieve better results than scikit-learn default scores.