Repository navigation
FIX always use logits in CalibratedClassifierCV - #34313
lorentzenchr merged 73 commits into
Conversation
|
I agree, we should definitively use the logits for sigmoid recalibration / Platt scaling. @ogrisel Could you grant me rights to push to your PR ? I'll try to merge main and update this draft PR. |
|
@antoinebaker you were already registered as a collaborator on my scikit-learn fork :) Please go ahead with the merge and update of this PR. |
|
Hi @ogrisel and @virchan, the PR is currently passing the CI. However I would like to refactor the code, in line with your code comments @ogrisel and your comment @virchan. I would greatly appreciate your feedback (see Comments section) to discuss future implementations ! With the help of cursor, here a summary of the current logic of
|
| Calibration method | Target logit space | Transformation |
|---|---|---|
| sigmoid / isotonic | OvR (“Bernoulli”) logits | z_k = logit(p_k) |
| temperature | Multinomial logits | z_k = log(p_k) - log(p_mean) |
decision_function
Inputs are scores s whose meaning varies by estimator.
| Calibration method | Target logit space | Current transformation |
|---|---|---|
| sigmoid / isotonic | OvR (“Bernoulli”) logits | Binary (1D): pass-through s (assumed positive-class log-odds). Multiclass (K>2): softmax(s) → p_k, then z_k = logit(p_k). |
| temperature | Multinomial logits | Pass-through s (assumed joint logits with p = softmax(s)). |
Comments
For me, the handling of predict_proba is correct and solves #34312. The handling of decision_function is more debatable. It seems to always assume "Multinomial logits"-like scores, and in particular converts them to Bernoulli logits for the sigmoid/isotonic calibration method.
Here are some implementation options I'd like to discuss:
- get rid of the
logit_preprocessingparameter. Instead we always decide based on the calibrationmethod(sigmoid vs softmax) andresponse_method_name(predict_proba vs decision_function) - only convert
predict_probafor now, letdecision_functionpassthrough. This would make the code much easier to understand. This would already fixes # 34312. - try to determine (for an estimator) if the
decision_functionscores are "morally" more Bernoulli vs Multinomial logits and convert based on that. But this seems difficult to do in general. - always convert the
decision_functionscores to the target logit space, even if they are in the correct logit space to start with. Currently done for thesigmoidmethod, but could be done for thetemperaturemethod as well.
I think I originally introduced the
I agree. |
|
@antoinebaker Let's first add temperature scaling to Let's also check that "sigmoid" logits preprocessing is always better or similar to "softmax" logits preprocessing for the two OvR methods. If all goes according to our plan, we can hard code the logits preprocessing logic and remove the empirical evaluation of the logits_processing parameter from that example. |
antoinebaker
left a comment
There was a problem hiding this comment.
I did a last quick review, LGTM !
I'd like to remove test_asymptotic_multiclass_calibration_improvement because I find this test hard to understand, but I'm fine if others want to keep it.
|
Once the review comments are addressed (mostly wording), it is good to go. |
Co-authored-by: Christian Lorentzen <[email protected]> Co-authored-by: Olivier Grisel <[email protected]>
|
I applied most of the suggestions from the last pass via github and will address the remaining feedback manually in new commits. |
|
Circle CI fails with: which is unrelated to this PR and observed on other PRs. Hopefully it's a transient problem on the circle ci infra rather than a config problem on our side. |
|
CI is green again \o/ and the plots still look good. I think I addressed all @lorentzenchr's feedback but I cannot approve my own PR :) |
|
Thanks for the reviews and the code/doc contributions to this PR @virchan @lorentzenchr and @antoinebaker! |
|
For me, the need of this fix was the most surprising. I just never looked up our exact code. |
Fixes: #34312
Note: this draft PR was started a long time ago. Work is needed to realign it with the current
mainbranch.