Plot visualization. Extra keyword arguments will be passed to :func:`matplotlib.pyplot.plot`. Parameters ---------- ax : Matplotlib Axes, default=None Axes object to plot on. If `None`, a new figure and axes is created. name
(self, *, ax=None, name=None, ref_line=True, **kwargs)
| 1426 | self.pos_label = pos_label |
| 1427 | |
| 1428 | def plot(self, *, ax=None, name=None, ref_line=True, **kwargs): |
| 1429 | """Plot visualization. |
| 1430 | |
| 1431 | Extra keyword arguments will be passed to |
| 1432 | :func:`matplotlib.pyplot.plot`. |
| 1433 | |
| 1434 | Parameters |
| 1435 | ---------- |
| 1436 | ax : Matplotlib Axes, default=None |
| 1437 | Axes object to plot on. If `None`, a new figure and axes is |
| 1438 | created. |
| 1439 | |
| 1440 | name : str, default=None |
| 1441 | Name for labeling curve. If `None`, use `estimator_name` if |
| 1442 | not `None`, otherwise no labeling is shown. |
| 1443 | |
| 1444 | ref_line : bool, default=True |
| 1445 | If `True`, plots a reference line representing a perfectly |
| 1446 | calibrated classifier. |
| 1447 | |
| 1448 | **kwargs : dict |
| 1449 | Keyword arguments to be passed to :func:`matplotlib.pyplot.plot`. |
| 1450 | |
| 1451 | Returns |
| 1452 | ------- |
| 1453 | display : :class:`~sklearn.calibration.CalibrationDisplay` |
| 1454 | Object that stores computed values. |
| 1455 | """ |
| 1456 | self.ax_, self.figure_, name = self._validate_plot_params(ax=ax, name=name) |
| 1457 | |
| 1458 | info_pos_label = ( |
| 1459 | f"(Positive class: {self.pos_label})" if self.pos_label is not None else "" |
| 1460 | ) |
| 1461 | |
| 1462 | default_line_kwargs = {"marker": "s", "linestyle": "-"} |
| 1463 | if name is not None: |
| 1464 | default_line_kwargs["label"] = name |
| 1465 | line_kwargs = _validate_style_kwargs(default_line_kwargs, kwargs) |
| 1466 | |
| 1467 | ref_line_label = "Perfectly calibrated" |
| 1468 | existing_ref_line = ref_line_label in self.ax_.get_legend_handles_labels()[1] |
| 1469 | if ref_line and not existing_ref_line: |
| 1470 | self.ax_.plot([0, 1], [0, 1], "k:", label=ref_line_label) |
| 1471 | self.line_ = self.ax_.plot(self.prob_pred, self.prob_true, **line_kwargs)[0] |
| 1472 | |
| 1473 | # We always have to show the legend for at least the reference line |
| 1474 | self.ax_.legend(loc="lower right") |
| 1475 | |
| 1476 | xlabel = f"Mean predicted probability {info_pos_label}" |
| 1477 | ylabel = f"Fraction of positives {info_pos_label}" |
| 1478 | self.ax_.set(xlabel=xlabel, ylabel=ylabel) |
| 1479 | |
| 1480 | return self |
| 1481 | |
| 1482 | @classmethod |
| 1483 | def from_estimator( |