-
-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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`, the name of the estimator | ||
is used. | ||
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. This is only true if 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. It is even different. If |
||
|
||
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) |
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
...?