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

Error message with sklearn function " 'RocCurveDisplay' has no attribute 'from_predictions' "

我正在尝试使用 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()

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

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

您的版本 0.24.1 不是最新版本,您需要升级到 scikit-learn 1.0 因为 from_predictions1.0[=15] 中受支持=]

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

pip install --upgrade scikit-learn