Repository navigation
Fix pos_label validation in multiclass scorers - #33473
Conversation
OmarManzoor
left a comment
There was a problem hiding this comment.
LGTM. Thank you @ogrisel
AnneBeyer
left a comment
There was a problem hiding this comment.
Thank you @ogrisel!
It feels a bit unintuitive to do nothing with "pos_lable" when it is explicitly passed but invalid, but I don't fully understand the discussions regarding setting it to None yet, so for now, leaving it unchecked and unchanged in the multiclass case seems fine to me.
(And getting rid of the re-raise in the DecisionBoundaryDisplay was also on my list.)
The problem is that for |
|
@lucyleeow any opinion on this? |
| - Fixed incorrect :class:`ValueError` when using | ||
| ``scoring="average_precision"`` or similar in model selection utilities such | ||
| as `model_selection.GridSearchCV` or `model_selection.cross_validate` with | ||
| multiclass classifiers. The ``pos_label`` parameter is only relevant for |
There was a problem hiding this comment.
From the public API, if one were to create a scorer with:
make_scorer(
average_precision_score,
response_method=("decision_function", "predict_proba"),
pos_label="invalid_label",
)will they still end up with this ValueError?
scikit-learn/sklearn/metrics/_ranking.py
Lines 280 to 284 in ceeffc5
There was a problem hiding this comment.
I will update the test accordingly.
There was a problem hiding this comment.
I updated the test to use public API based on your suggestion 4317474. I think we can leave the changelog entry as is though. Both using make_scorer manually or passing score="average_precision" to a validation tool are valid ways to trigger the problem in the private _response.py module.
lucyleeow
left a comment
There was a problem hiding this comment.
LGTM - some nits around the other 'response' function docs.
| classes = estimator.classes_ | ||
| target_type = type_of_target(classes) | ||
|
|
||
| if target_type in ("binary", "multiclass"): |
There was a problem hiding this comment.
I can't understand why "multiclass" used to be here. Looking at other places where multiclass data may be input to this function: CalibratedClassifierCV, partial_dependence - we never use pos_label. Decision boundary is the only place that it is used but it re-raises a more informative error... 🤔
lucyleeow
left a comment
There was a problem hiding this comment.
Mis-clicked, was meant to approve
Agree that it is not ideal to silently ignore |
Co-authored-by: Lucy Liu <[email protected]>
While working on an array API integration test (#32873) that calls
cross_validatewithscoring="average_precision"on a multiclass classification problem with string class labels, I discovered that our scorer wrongfully attempts to validatepos_labeland raiseValueErrorbecausepos_label=1(the current default inaverage_precision_score) is not one of the observedclf.classes_.I isolated the problem with a minimal unit test so that we can fix that independently of the array API concerns discovered with this integration test.