Fix calibration_curve docstring for empty bins#12926
Merged
jnothman merged 2 commits intoscikit-learn:masterfrom Jan 13, 2019
Merged
Fix calibration_curve docstring for empty bins#12926jnothman merged 2 commits intoscikit-learn:masterfrom
jnothman merged 2 commits intoscikit-learn:masterfrom
Conversation
The code for calibration_curve will remove bins that are empty, thus the number of bins in the return value may be smaller than n_bins. This commit fixes the docstring to document this (existing) behavior.
jnothman
reviewed
Jan 7, 2019
sklearn/calibration.py
Outdated
| ------- | ||
| prob_true : array, shape (n_bins,) | ||
| The true probability in each bin (fraction of positives). | ||
| prob_true : array, shape (n_non_empty_bins,) |
Member
There was a problem hiding this comment.
I wonder if this should be expressed as (n_bins,) or smaller to avoid confusion. or (n_bins,) with a comment below.
Contributor
Author
There was a problem hiding this comment.
I think (n_bins,) or smaller would work well. If we just had (n_bins,) on the first line, however, I'd worry that it would be easy to miss the caveat/comment below. A footnote would be another option, but your first suggestion seems clearest to me. Should I modify the pull request?
Member
|
Yes, please add a commit
|
Changed `shape (n_non_empty_bins)` to `shape (n_bins,) or smaller` based on reviewer feedback of pull request.
jnothman
approved these changes
Jan 13, 2019
jnothman
pushed a commit
to jnothman/scikit-learn
that referenced
this pull request
Feb 19, 2019
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
…ing (scikit-learn#12926)" This reverts commit f1e78a6.
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
…ing (scikit-learn#12926)" This reverts commit f1e78a6.
koenvandevelde
pushed a commit
to koenvandevelde/scikit-learn
that referenced
this pull request
Jul 12, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current docstring for calibration.calibration_curve states that the return values are of shape (n_bins,) The code for calibration_curve however, will remove bins that are empty (which is not mentioned in the current docstring), thus the number of bins in the return value may be smaller than n_bins. This commit fixes the docstring to document the (existing) behavior of removing empty bins.
What does this implement/fix? Explain your changes.
When a bin is empty, calibration_curve will remove it from the list of bins, resulting in return values with less than n_bins:
The existing documentation for this function makes no mention of removing empty bins, however, and states that the return values with be of shape (n_bins,):
Obviously it's best of the documentation matches the behavior of the code, and changing the behavior of the code would risk breaking existing uses of the code. This check in thus updates the documentation to include the behavior of dropping empty bins.
Any other comments?
I encountered this in with real data when trying to generate confidence intervals for a calibration curve using cross validation. The model used weakly correlating features and thus high predicted probabilities were rare and not present in some folds. This lead to differing numbers of bins in each fold causing errors downstream, and the undocumented behavior slowed down the debugging process.
It some cases (such as mine) it would be better to support the behavior of the original documentation (always returning the requested number of bins, even if some are empty) by returning NaNs for empty bins which the end user can then handle appropriately. This could be safely added with a parameter such as
drop_emptywhich could default toTruefor compatibility. I would be happy to create the pull request if there is interest, but I am assuming there is not enough interest to justify maintaining and testing another control path in the code.