sklearn 函数的错误消息“‘RocCurveDisplay’没有属性‘from_predictions’”

Jul*_*the 6 python roc scikit-learn

我正在尝试使用https://scikit-learn.org/stable/modules/ generated/sklearn.metrics.RocCurveDisplay.html#sklearn.metrics.RocCurveDisplay.from_predictions 中介绍的 sklearn 函数 RocCurveDisplay.from_predictions 。我像这样运行该函数:

from sklearn.metrics import RocCurveDisplay

true = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
       1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0.])

prediction = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0.,
       1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 1., 1., 0., 0.])

RocCurveDisplay.from_predictions(true,prediction)
plt.show()
Run Code Online (Sandbox Code Playgroud)

我收到错误消息“AttributeError:类型对象‘RocCurveDisplay’没有属性‘from_predictions’”。

这是版本问题吗?我使用的是最新的0.24.1

Luk*_*uke 8

您的版本0.24.1不是最新版本,您需要升级到 scikit-learn ,1.0from_predictions1.0

您可以使用以下方式升级:

pip install --upgrade scikit-learn
Run Code Online (Sandbox Code Playgroud)

  • 值得一提的是,该版本仅支持python 3.7及以上版本 (3认同)