New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG] Enforcing strict monotonicity for IsotonicRegression #17790
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dsleo ,
I understand this is still WIP but I took a quick look
we should also add details in the User guides of both calibration and isotonic
It should be False for CalibratedClassifierCV and IsotonicRegression so that results don't change in the next versions |
doctstring wording Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Thanks @NicolasHug for the review ! I did the modifications following your comments and I've added some description in the calibration's user guide. This should ready for full review now ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dsleo
I think we should also detail in the User Guide of isotonic how the strict mode works.
We could also udpate the example https://scikit-learn.org/dev/auto_examples/miscellaneous/plot_isotonic_regression.html#sphx-glr-auto-examples-miscellaneous-plot-isotonic-regression-py to illustrate the difference between strict and non-strict mode.
(Also, not directly related to this PR, but if you could include a link to that example in the User Guide it would be great!)
I've made the changes according to your comments and update the example. A few things to note:
I'll try to find the time tomorrow to fill in the details in the UG on the strict mode. |
little ping @NicolasHug in case this was drown in all the others issues and PRs :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A note about out_of_bounds
that we should fix.
I think this shows that we should add strict=True/False
with pytest parameterize to more tests.
Or at least to oob tests - test_isotonic_regression_oob_clip
, test_isotonic_regression_oob_nan
, test_isotonic_regression_oob_raise
etc
sklearn/isotonic.py
Outdated
When set to `True`, points outside the training domain will be | ||
extrapolated, unless `out_of_bounds="clip"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we want to add another option to out_of_bounds
if we want to extrapolate values outside of the training domain.
It doesn't make sense that we give extrapolated values when out_of_bounds
is: 'nan' or 'raise' (and it isn't consistent with the behaviour when strict=False
). If we want to offer extrapolate option, we should add an 'extrapolate' option to out_of_bounds
. But I am also not sure if it a good idea to extrapolate though @ogrisel and @NicolasHug will know more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add a .. versionadded::
here
Sorry for the delay in following up on this ! @lucyleeow, I've simplified the code, no more unnecessary extrapolation or issues with Regarding the example you propose, when removing flat segments, we can fix both extremities of the interval (see here). iso_strict = IsotonicRegression(strict=True)
iso_strict.fit(X, y)
iso_strict.predict(np.array([0.9]))
array([0.98853113]) And this is the corresponding curve with This should now be ready for a second review then. |
@ogrisel thanks for the heads up. I am not familiar with centered isotonic regression and its uses but if we can enforce monotonicity at the edges that would also handle this. Perhaps through two parameters, |
Let's centralize the discussion on the centered isotonic PR directly. |
See #21454. |
Reference Issues/PRs
As per our discussion, this fixes issue #16321.
What does this implement/fix? Explain your changes.
IsotonicRegression
not being strictly monotonic, calibration usingIsotonicRegression
have its rank-based metrics changes. This PR adds astrict
argument toIsotonicRegression
to enforce strict monotonicity by keeping only the unique values of the thresholdsy_thresholds_
.Any other comments?
Not sure whether the
strict
argument should default toTrue
forCalibratedClassifierCV
if the selected method isisotonic
?