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
order of returned probabilites unclear for cross_val_predict with method=predict_proba #7863
Cross_val_predict has a new method parameter which is typically set to "predict_proba" to return probabilities for each class.
However the order of the classes returned is unclear. Either self.classes_ needs to be set; or the results need to be returned in a predictable order. Otherwise we have a list of probabilities for each class but no way to know which column relates to which class.
After running a few tests on the iris dataset using LogisticRegression as the estimator, it became clear that the order of the classes appearing did not matter in the final result. This gives a simple and clear explanation.
Iris aside, it's possible to create a cross-validation strategy that will
land up with only a subset of the classes being present in the training
data for a particular training set. This should be handled.
Firstly the documentation should point out that the classes will be in
sorted order, and this should, in theory at least, be confirmed, reordering
if necessary, from the underlying estimators.
True, we could miss out on a few observations in cross-validation. As for the confirmation of the classes being sorted, since these lines of the cross_val_predict function already ensure that only estimators capable of calculating the probability are passed 'predict_proba' as the method, and all such estimators return the classes in sorted order, do we need any other mode of confirmation?
Please correct me if I misunderstood what you intended to say.
ifnotcallable(getattr(estimator, method)):
raiseAttributeError('{} not implemented in estimator'
.format(method))
True, we could miss out on a few observations in cross-validation. As for
the confirmation of the classes being sorted, since these lines of the
cross_val_predict function already ensure that only estimators capable of
calculating the probability are passed 'predict_proba' as the method, and
all such estimators return the classes in sorted order, do we need any
other mode of confirmation?
Please correct me if I misunderstood what you intended to say.
if not callable(getattr(estimator, method)):
raise AttributeError('{} not implemented in estimator'
.format(method))
Then how about, in the _fit_and_predict function, I retrieve the classes_ attribute, make a dictionary of the column indices and the class labels, sort them on the class labels and apply the transformation to the predictions, thereby ensuring that a sorted result is returned?
Then how about, in the fit_and_predict function, I retrieve the 'classes'
attribute, make a dictionary of the column indices and the class labels,
sort them and apply the transformation to the predictions, thereby ensuring
that a sorted result is returned?
That would be a good idea as it would make sure 3rd party classifiers used the same standard. I know it works today for LogisticRegression and RandomForestClassifier. However I am unsure for XGBClassifier as that is outside sklearn.
Activity
jnothman commentedon Nov 14, 2016
Yes, I suppose this (and disagreements in the set of classes between splits) was overlooked.
(For internal models, I'm fairly sure that
classes_is always alphabetically ordered.)dalmia commentedon Nov 15, 2016
Can I start working on this?
dalmia commentedon Nov 16, 2016
After running a few tests on the iris dataset using LogisticRegression as the estimator, it became clear that the order of the classes appearing did not matter in the final result. This gives a simple and clear explanation.
jnothman commentedon Nov 16, 2016
Iris aside, it's possible to create a cross-validation strategy that will
land up with only a subset of the classes being present in the training
data for a particular training set. This should be handled.
Firstly the documentation should point out that the classes will be in
sorted order, and this should, in theory at least, be confirmed, reordering
if necessary, from the underlying estimators.
On 16 November 2016 at 11:41, Aman Dalmia [email protected] wrote:
dalmia commentedon Nov 16, 2016
True, we could miss out on a few observations in cross-validation. As for the confirmation of the classes being sorted, since these lines of the cross_val_predict function already ensure that only estimators capable of calculating the probability are passed 'predict_proba' as the method, and all such estimators return the classes in sorted order, do we need any other mode of confirmation?
Please correct me if I misunderstood what you intended to say.
jnothman commentedon Nov 16, 2016
Well, we don't promise that all return classes in sorted order; all store
classes in
.classes_On 16 November 2016 at 14:44, Aman Dalmia [email protected] wrote:
dalmia commentedon Nov 16, 2016
Then how about, in the
_fit_and_predictfunction, I retrieve theclasses_attribute, make a dictionary of the column indices and the class labels, sort them on the class labels and apply the transformation to the predictions, thereby ensuring that a sorted result is returned?jnothman commentedon Nov 16, 2016
That sort of thing, yes
On 16 November 2016 at 16:23, Aman Dalmia [email protected] wrote:
simonm3 commentedon Nov 16, 2016
That would be a good idea as it would make sure 3rd party classifiers used the same standard. I know it works today for LogisticRegression and RandomForestClassifier. However I am unsure for XGBClassifier as that is outside sklearn.