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
predict_scores is a method to unify predict methods which output a score such as decision_function, predict_proba, etc. It should return a [n_samples, n_classes] array containing scores (the bigger, the more likely to choose the corresponding class).
The method signature should be predict_scores(self, X, score="margin|proba|log_proba|...") or maybe predict_scores(self, X, score_func="margin|proba|log_proba|...").
TODO list (please comment):
Add a PredictorMixin which implements predict_scores (just calling the underlying decision_function, predict_proba, etc if present and raising a NotImplementedError if not)
Add PredictorMixin to objects which have a decision_function or a predict_proba method
Currently, decision_function returns an array of shape [n_samples, 1] in the binary case. Break API to return [n_samples, 2] or handle decision_function separately in PredictorMixin.predict_scores. I suggest we create a new method predict_margin which is basically the same as decision_function but with the array shape fixed and deprecate decision_function (keep it for two releases).
Override predict_scores in KMeans and other clustering modules to return the opposite of the distances to the clusters.
Implement predict_log_proba as the log of predict_proba in PredictorMixin (?)
Change multiclass module to internally use predict_scores (currently it looks for decision_function and predict_proba)
Add predict_scores to the multiclass estimators. OneVsOneClassifier and OutputCodeClassifier will need to override predict_scores
If it's going to raise NotImplementedError whenever a score is not available, then we might as well add predict_scores to ClassifierMixin.
As for predict_log_proba, a default implementation as the log of predict_proba would be fine as long as the reverse is also true: predict_proba as the exp of predict_log_proba. Probabilistic classifiers (such as NB) commonly work in logspace. This might get tricky, though.
As for predict_log_proba, a default implementation as the log of predict_proba would be fine as long as the reverse is also true: predict_proba as the exp of predict_log_proba. Probabilistic classifiers (such as NB) commonly work in logspace. This might get tricky, though.
How do you plan to do it? (Won't we end up with a recursive definition?)
I have not had the time to follow the details but I would rather avoid to add method to the mixins that raise NotImplementedError: the motivation is that we give incentives to use duck typing to discover the capabilities of an estimator and base methods that raise NotImplementedError feels adversary to duck typing-style introspection.
I have not had the time to follow the details but I would rather avoid to add method to the mixins that raise NotImplementedError: the motivation is that we give incentives to use duck typing to discover the capabilities of an estimator and base methods that raise NotImplementedError feels adversary to duck typing-style introspection.
What should we do in predict_scores when the underlying method (e.g. predict_proba) is not defined. Just let Python raise an AttributeError? BTW, the user can still do hasattr(clf, "predict_proba"), the question here is just, what to do inside predict_scores.
+1 for @agramfort's proposal (with an exception to call decision_function for score=margin). This seems like the simplest option to me.
When we tackle this issue, I would like to deprecate decision_function to fix the shape issue in the binary case, if that's ok with everyone. I'm thinking of calling the new method predict_margin instead.
When we tackle this issue, I would like to deprecate decision_function to fix the shape issue in the binary case, if that's ok with everyone. I'm thinking of calling the new method predict_margin instead.
I'd really like us to stop changing APIs. We are massively used nowadays.
There's been a printed book published referencing us, gazillion of blog
posts, and who knows how much code in different labs using the scikit. We
need to be very careful about changing API.
This is not a vote completely against, as I haven't dedicated much mental
bandwidth to this issue (I am crawling under work currently). But I'd
like the reasons for any API change to be clearly thought through and
explained on the mailing list.
Well, as discussed on the mailing list, the current API is completely inconsistent especially in terms of shapes. As long as we deprecate methods with warnings, preserve backward compatibility and document the replacement API this is fine.
I'd really like us to stop changing APIs. We are massively used nowadays. There's been a printed book published referencing us, gazillion of blog posts, and who knows how much code in different labs using the scikit. We need to be very careful about changing API.
If we fix the shape issue of decision_function without renaming it, this will break existing code (in the binary case). So I prefer to fix the shape issue in a new method predict_margin and deprecate decision_function. Also decision_function is probably used by advanced users only.
@mblondel would you be ok with closing this? We now have consistent shapes, so I personally don't really see the need for predict_score any more. wdyt?
I wouldn't mind but the goal of predict_score was not only to have consistent shapes but also to have a unique method with a notion of score (the higher, the more likely to assign the class). This is useful for the multiclass module and will also be for calibration I guess.
You think a try-except is not a good solution?
We could put the try-except in the mixin instead of the multi class.
That would be very easy to do, but would add another function to the user-interface.
Not sure this is beneficial.
@agramfort this issue is about getting continuous "confidence" scores in a
consistent manner from regressors and classifiers. I am not saying adding a
new method is the solution but I hope we can reach a concensus on a
solution soon (c.f. recent discussion on the ML). score_samples is
something different.
@iskandr That would indeed be possible (and also add decision_function as an alias to predict in regressors in order to be able to do binary classification and ranking). I personally see predict as what you get when you take the row-wise argmax of decision_function. Of course there are sometimes several ways of defining decision_function so that this is true. The only problem is that in some classifiers decision_function has inconsistent shape in the binary case: (n_samples) instead of (n_samples, 2).
BTW if you're at NIPS I would be glad to have a chat about parakeet.
@mblondel I guess worries about either (1) breaking compatibility or (2) muddying the interface by adding a nearly identical method; is where this issue got stalled in 2012. Which of these two options seem preferable to you? I personally like the suggestion to deprecate decision_function and make a shape consistent predict_score or predict_margin.
In either case, it seems like classifier with predict_proba should always have a default implementation of either decision_function and, if we add the method, predict_score.
(I'm at NIPS! Are you going the poster session later today? I'll be there around 3 or 4)
I can introduce you two ;)
For the two class case the decision function is (n_samples,) consistently in all models.
So adding a default implementation of decision_function would remove the need for ducktyping in many cases. It will still require an if for the decision function in some cases, but I think that shouldn't really be that big an issue.
I was talking of the inconsistency between the n_classes=2 and n_classes>2 cases. This requires branching in user code to handle the different shapes. Not the end of the world but that's inconvenient :)
It is very unfortunate that this was not implemented, the fact is 'predict_proba' is both false and misleading people believing that scikit-learn produces 'probabilities'.
In fact it produces miscalibrated class scores that not only costs companies money but is very dangerous in high risk applications including health, medicine, self driving cars, finance and many others.
Misnomering the function as 'predict_proba' is not only incorrect, but causes harm to anyone who uses it and is irresponsible act from what is most used machine learning library. Not only the function is clearly misleading but the documentation does not even explain that class scores are miscalibrated that has been documents in countless academic literature for over 20 years.
Activity
larsmans commentedon Oct 19, 2011
If it's going to raise
NotImplementedErrorwhenever a score is not available, then we might as well addpredict_scorestoClassifierMixin.As for
predict_log_proba, a default implementation as the log ofpredict_probawould be fine as long as the reverse is also true:predict_probaas the exp ofpredict_log_proba. Probabilistic classifiers (such as NB) commonly work in logspace. This might get tricky, though.mblondel commentedon Oct 19, 2011
Any thought, others? (@ogrisel, @GaelVaroquaux, ...)
How do you plan to do it? (Won't we end up with a recursive definition?)
larsmans commentedon Oct 19, 2011
I think we'd have to rename the methods in derived classes to
_predict_probaand_predict_log_probato infinite recursion.ogrisel commentedon Oct 19, 2011
I have not had the time to follow the details but I would rather avoid to add method to the mixins that raise
NotImplementedError: the motivation is that we give incentives to use duck typing to discover the capabilities of an estimator and base methods that raiseNotImplementedErrorfeels adversary to duck typing-style introspection.mblondel commentedon Oct 19, 2011
What should we do in
predict_scoreswhen the underlying method (e.g.predict_proba) is not defined. Just let Python raise anAttributeError? BTW, the user can still dohasattr(clf, "predict_proba"), the question here is just, what to do insidepredict_scores.agramfort commentedon Oct 19, 2011
I had in mind just adding in ClassifierMixin
this method:
larsmans commentedon Oct 19, 2011
+1 for @agramfort's proposal (with an exception to call
decision_functionforscore=margin). This seems like the simplest option to me.mblondel commentedon Oct 19, 2011
When we tackle this issue, I would like to deprecate
decision_functionto fix the shape issue in the binary case, if that's ok with everyone. I'm thinking of calling the new methodpredict_margininstead.GaelVaroquaux commentedon Oct 19, 2011
I'd really like us to stop changing APIs. We are massively used nowadays.
There's been a printed book published referencing us, gazillion of blog
posts, and who knows how much code in different labs using the scikit. We
need to be very careful about changing API.
This is not a vote completely against, as I haven't dedicated much mental
bandwidth to this issue (I am crawling under work currently). But I'd
like the reasons for any API change to be clearly thought through and
explained on the mailing list.
ogrisel commentedon Oct 19, 2011
Well, as discussed on the mailing list, the current API is completely inconsistent especially in terms of shapes. As long as we deprecate methods with warnings, preserve backward compatibility and document the replacement API this is fine.
mblondel commentedon Oct 19, 2011
If we fix the shape issue of
decision_functionwithout renaming it, this will break existing code (in the binary case). So I prefer to fix the shape issue in a new methodpredict_marginand deprecatedecision_function. Alsodecision_functionis probably used by advanced users only.amueller commentedon Oct 7, 2012
@mblondel would you be ok with closing this? We now have consistent shapes, so I personally don't really see the need for
predict_scoreany more. wdyt?mblondel commentedon Oct 7, 2012
I wouldn't mind but the goal of
predict_scorewas not only to have consistent shapes but also to have a unique method with a notion of score (the higher, the more likely to assign the class). This is useful for the multiclass module and will also be for calibration I guess.amueller commentedon Oct 7, 2012
You think a try-except is not a good solution?
We could put the try-except in the mixin instead of the multi class.
That would be very easy to do, but would add another function to the user-interface.
Not sure this is beneficial.
2 remaining items
raghavrv commentedon Dec 6, 2014
okay :)
agramfort commentedon Dec 6, 2014
There is a score_samples method in PCA
mblondel commentedon Dec 6, 2014
@agramfort this issue is about getting continuous "confidence" scores in a
consistent manner from regressors and classifiers. I am not saying adding a
new method is the solution but I hope we can reach a concensus on a
solution soon (c.f. recent discussion on the ML).
score_samplesissomething different.
iskandr commentedon Dec 10, 2014
Would it be possible to equip every classifier with a default implementation of
decision_functionbased on e.g. log probabilities?mblondel commentedon Dec 11, 2014
@iskandr That would indeed be possible (and also add
decision_functionas an alias topredictin regressors in order to be able to do binary classification and ranking). I personally seepredictas what you get when you take the row-wise argmax ofdecision_function. Of course there are sometimes several ways of definingdecision_functionso that this is true. The only problem is that in some classifiersdecision_functionhas inconsistent shape in the binary case:(n_samples)instead of(n_samples, 2).BTW if you're at NIPS I would be glad to have a chat about parakeet.
iskandr commentedon Dec 11, 2014
@mblondel I guess worries about either (1) breaking compatibility or (2) muddying the interface by adding a nearly identical method; is where this issue got stalled in 2012. Which of these two options seem preferable to you? I personally like the suggestion to deprecate
decision_functionand make a shape consistentpredict_scoreorpredict_margin.In either case, it seems like classifier with
predict_probashould always have a default implementation of eitherdecision_functionand, if we add the method,predict_score.(I'm at NIPS! Are you going the poster session later today? I'll be there around 3 or 4)
amueller commentedon Dec 11, 2014
I can introduce you two ;)
For the two class case the decision function is
(n_samples,)consistently in all models.So adding a default implementation of
decision_functionwould remove the need for ducktyping in many cases. It will still require an if for the decision function in some cases, but I think that shouldn't really be that big an issue.mblondel commentedon Dec 11, 2014
This is my favored solution too, since I want to fix the shape inconsistency issue but would rather not break compatibility.
amueller commentedon Dec 11, 2014
I'm not sure which inconsistency you mean. The fact that predict_proba has a diffferent shape from decision function? Why is that a problem?
iskandr commentedon Dec 11, 2014
@amueller Are there any binary classifiers whose
decision_functionreturns an array with shape(n_samples, 2)?mblondel commentedon Dec 11, 2014
I was talking of the inconsistency between the n_classes=2 and n_classes>2 cases. This requires branching in user code to handle the different shapes. Not the end of the world but that's inconvenient :)
amueller commentedon Aug 28, 2015
I think we kind of decided on not changing that, right? @mblondel would be ok to close?
mblondel commentedon Aug 29, 2015
Alright, closing :)
valeman commentedon Oct 25, 2023
It is very unfortunate that this was not implemented, the fact is 'predict_proba' is both false and misleading people believing that scikit-learn produces 'probabilities'.
In fact it produces miscalibrated class scores that not only costs companies money but is very dangerous in high risk applications including health, medicine, self driving cars, finance and many others.
Misnomering the function as 'predict_proba' is not only incorrect, but causes harm to anyone who uses it and is irresponsible act from what is most used machine learning library. Not only the function is clearly misleading but the documentation does not even explain that class scores are miscalibrated that has been documents in countless academic literature for over 20 years.