Загрузка
CalibrationDisplayRead more about calibration in the User Guide and more about the scikit-learn visualization API in Visualizations.
For an example on how to use the visualization, see Probability Calibration curves.
The proportion of samples whose class is the positive class (fraction of positives), in each bin.
The mean predicted probability in each bin.
Probability estimates for the positive class, for each sample.
Name of estimator. If None, the estimator name is not shown.
The positive class when calibration curve computed.
If not None, this value is displayed in the x- and y-axes labels.
Calibration curve.
Axes with calibration curve.
Figure containing the curve.
>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.calibration import calibration_curve, CalibrationDisplay
>>> X, y = make_classification(random_state=0)
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, random_state=0)
>>> clf = LogisticRegression(random_state=0)
>>> clf.fit(X_train, y_train)
LogisticRegression(random_state=0)
>>> y_prob = clf.predict_proba(X_test)[:, 1]
>>> prob_true, prob_pred = calibration_curve(y_test, y_prob, n_bins=10)
>>> disp = CalibrationDisplay(prob_true, prob_pred, y_prob)
>>> disp.plot()
<...>
Plot calibration curve using a binary classifier and data.
A calibration curve, also known as a reliability diagram, uses inputs from a binary classifier and plots the average predicted probability for each bin against the fraction of positive classes, on the y-axis.
Extra keyword arguments will be passed to
matplotlib.pyplot.plot.
Read more about calibration in the User Guide and more about the scikit-learn visualization API in Visualizations.
Fitted classifier or a fitted in which the last estimator is a classifier. The classifier must have a method.
Plot calibration curve using true labels and predicted probabilities.
Calibration curve, also known as reliability diagram, uses inputs from a binary classifier and plots the average predicted probability for each bin against the fraction of positive classes, on the y-axis.
Extra keyword arguments will be passed to
matplotlib.pyplot.plot.
Read more about calibration in the User Guide and more about the scikit-learn visualization API in Visualizations.
True labels.
Plot visualization.
Extra keyword arguments will be passed to
matplotlib.pyplot.plot.
Axes object to plot on. If None, a new figure and axes is
created.
Name for labeling curve. If None, use estimator_name if
not None, otherwise no labeling is shown.
If True, plots a reference line representing a perfectly
calibrated classifier.
Keyword arguments to be passed to matplotlib.pyplot.plot.
CalibrationDisplayObject that stores computed values.
Input values.
Binary target values.
Number of bins to discretize the [0, 1] interval into when calculating the calibration curve. A bigger number requires more data.
Strategy used to define the widths of the bins.
'uniform': The bins have identical widths.
'quantile': The bins have the same number of samples and depend
on predicted probabilities.
The positive class when computing the calibration curve.
By default, estimators.classes_[1] is considered as the
positive class.
Name for labeling curve. If None, the name of the estimator is
used.
Axes object to plot on. If None, a new figure and axes is
created.
If True, plots a reference line representing a perfectly
calibrated classifier.
Keyword arguments to be passed to matplotlib.pyplot.plot.
CalibrationDisplay.Object that stores computed values.
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.calibration import CalibrationDisplay
>>> X, y = make_classification(random_state=0)
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, random_state=0)
>>> clf = LogisticRegression(random_state=0)
>>> clf.fit(X_train, y_train)
LogisticRegression(random_state=0)
>>> disp = CalibrationDisplay.from_estimator(clf, X_test, y_test)
>>> plt.show()
The predicted probabilities of the positive class.
Number of bins to discretize the [0, 1] interval into when calculating the calibration curve. A bigger number requires more data.
Strategy used to define the widths of the bins.
'uniform': The bins have identical widths.
'quantile': The bins have the same number of samples and depend
on predicted probabilities.
The positive class when computing the calibration curve.
When pos_label=None, if y_true is in {-1, 1} or {0, 1},
pos_label is set to 1, otherwise an error will be raised.
Name for labeling curve.
Axes object to plot on. If None, a new figure and axes is
created.
If True, plots a reference line representing a perfectly
calibrated classifier.
Keyword arguments to be passed to matplotlib.pyplot.plot.
CalibrationDisplay.Object that stores computed values.
>>> import matplotlib.pyplot as plt
>>> from sklearn.datasets import make_classification
>>> from sklearn.model_selection import train_test_split
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.calibration import CalibrationDisplay
>>> X, y = make_classification(random_state=0)
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, random_state=0)
>>> clf = LogisticRegression(random_state=0)
>>> clf.fit(X_train, y_train)
LogisticRegression(random_state=0)
>>> y_prob = clf.predict_proba(X_test)[:, 1]
>>> disp = CalibrationDisplay.from_predictions(y_test, y_prob)
>>> plt.show()