-
-
Notifications
You must be signed in to change notification settings - Fork 25k
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
FIX use same API for CalibrationDisplay than other Display #21031
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -980,8 +980,8 @@ class CalibrationDisplay: | |
y_prob : ndarray of shape (n_samples,) | ||
Probability estimates for the positive class, for each sample. | ||
|
||
name : str, default=None | ||
Name for labeling curve. | ||
estimator_name : str, default=None | ||
Name of estimator. If None, the estimator name is not shown. | ||
|
||
Attributes | ||
---------- | ||
|
@@ -1022,11 +1022,11 @@ class CalibrationDisplay: | |
<...> | ||
""" | ||
|
||
def __init__(self, prob_true, prob_pred, y_prob, *, name=None): | ||
def __init__(self, prob_true, prob_pred, y_prob, *, estimator_name=None): | ||
self.prob_true = prob_true | ||
self.prob_pred = prob_pred | ||
self.y_prob = y_prob | ||
self.name = name | ||
self.estimator_name = estimator_name | ||
|
||
def plot(self, *, ax=None, name=None, ref_line=True, **kwargs): | ||
"""Plot visualization. | ||
|
@@ -1041,7 +1041,8 @@ def plot(self, *, ax=None, name=None, ref_line=True, **kwargs): | |
created. | ||
|
||
name : str, default=None | ||
Name for labeling curve. | ||
Name for labeling curve. If `None`, use `estimator_name` if | ||
not `None`, otherwise no labeling is shown. | ||
|
||
ref_line : bool, default=True | ||
If `True`, plots a reference line representing a perfectly | ||
|
@@ -1061,8 +1062,7 @@ def plot(self, *, ax=None, name=None, ref_line=True, **kwargs): | |
if ax is None: | ||
fig, ax = plt.subplots() | ||
|
||
name = self.name if name is None else name | ||
self.name = name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree that this is weird, maybe it's left over from a previous iteration/API and I forgot to change. |
||
name = self.estimator_name if name is None else name | ||
|
||
line_kwargs = {} | ||
if name is not None: | ||
|
@@ -1298,6 +1298,9 @@ def from_predictions( | |
prob_true, prob_pred = calibration_curve( | ||
y_true, y_prob, n_bins=n_bins, strategy=strategy | ||
) | ||
name = name if name is not None else "Classifier" | ||
|
||
disp = cls(prob_true=prob_true, prob_pred=prob_pred, y_prob=y_prob, name=name) | ||
disp = cls( | ||
prob_true=prob_true, prob_pred=prob_pred, y_prob=y_prob, estimator_name=name | ||
) | ||
return disp.plot(ax=ax, ref_line=ref_line, **kwargs) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
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.
nitpick:
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.
To be pedantic there is no label shown in the plot only if
self.estimator
isNone
and in theplot
methodname
is alsoNone
...?