我试图按照sklearn文档中提供的example绘制交叉验证的接收器操作特征(ROC)曲线。但是,下面的导入在python2
和python3
中给出了ImportError
。
from sklearn.metrics import plot_roc_curve
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name plot_roc_curve
python-2.7
sklearn版本:0.20.2.
python-3.6
sklearn版本:0.21.3.
我发现下面的导入工作正常,但它与plot_roc_curve
不太一样。
from sklearn.metrics import roc_curve
plot_roc_curve
是否已弃用?谁能试一下代码,如果可以的话,让我知道sklearn的版本?
6条答案
按热度按时间wooyq4lh1#
plot_roc_curve已在1.2版中删除。从1.2开始,改用RocCurveDisplay:
sklearn 1.2之前:
从sklearn 1.2:
p4tfgftt2#
安装scikit-plot并从那里导入度量:
tcbh2hod3#
Plotting API在0.22版本中引入。here, Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4. Scikit-learn now requires Python 3.5 or newer.
3gtaxfhh4#
我用
conda update --all
更新了Conda
,然后将scikit-learn
更新到最新版本,对我来说是conda install scikit-learn=0.23.2
,并重新启动了内核。从那以后,我的错误就消失了。xesrikrc5#
正如sklearn的官方文档所提到的:函数
plot_roc_curve
在1.0中被弃用,并将在1.2中被删除。如果您想了解更多细节,请参阅here。使用类方法之一:
sklearn.metric.RocCurveDisplay.from_predictions
或sklearn.metric.RocCurveDisplay.from_estimator
。如果您想了解更多详细信息,请参阅此处。jvidinwx6#
为
使用
RocCurveDisplay
而不是from sklearn.metrics import RocCurveDisplay
中的plot_roc_curve