当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python sklearn CalibrationDisplay.from_predictions用法及代码示例


本文简要介绍python语言中 sklearn.calibration.CalibrationDisplay.from_predictions 的用法。

用法:

classmethod from_predictions(y_true, y_prob, *, n_bins=5, strategy='uniform', name=None, ref_line=True, ax=None, **kwargs)

使用真实标签和预测概率绘制校准曲线。

校准曲线,也称为可靠性图,使用来自二元分类器的输入,并在 y 轴上绘制每个 bin 的平均预测概率与正类的比例。

额外的关键字参数将传递给 matplotlib.pyplot.plot

在用户指南中阅读有关校准的更多信息,并在 Visualizations 中阅读有关 scikit-learn 可视化 API 的更多信息。

参数

y_true形状类似数组 (n_samples,)

真正的标签。

y_prob形状类似数组 (n_samples,)

正类的预测概率。

n_bins整数,默认=5

计算校准曲线时将 [0, 1] 区间离散化为的 bin 数。更大的数字需要更多的数据。

strategy{‘uniform’, ‘quantile’},默认='uniform'

用于定义 bin 宽度的策略。

  • 'uniform':箱子具有相同的宽度。
  • 'quantile':bin 具有相同数量的样本并取决于预测概率。
namestr,默认=无

标记曲线的名称。

ref_line布尔,默认=真

如果 True ,绘制代表完美校准分类器的参考线。

axmatplotlib 轴,默认=无

要绘制的轴对象。如果 None ,则创建一个新的图形和轴。

**kwargsdict

要传递给 matplotlib.pyplot.plot 的关键字参数。

返回

displayCalibrationDisplay

存储计算值的对象。

例子

>>> 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()
sklearn-calibration-CalibrationDisplay-2.png

相关用法


注:本文由纯净天空筛选整理自scikit-learn.org大神的英文原创作品 sklearn.calibration.CalibrationDisplay.from_predictions。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。