问题描述
今天遇到这样一个问题,耽误了很多时间:AttributeError: module 'sklearn.metrics' has no attribute 'plot_roc_curve',具体问题如下
>>> import matplotlib.pyplot as plt # doctest: +SKIP >>> from sklearn import datasets, metrics, model_selection, svm >>> X, y = datasets.make_classification(random_state=0) >>> X_train, X_test, y_train, y_test = model_selection.train_test_split( X, y, random_state=0) >>> clf = svm.SVC(random_state=0) >>> clf.fit(X_train, y_train) SVC(random_state=0) >>> metrics.plot_roc_curve(clf, X_test, y_test) # doctest: +SKIP >>> plt.show() # doctest: +SKIPAttributeError: module 'sklearn.metrics' has no attribute 'plot_roc_curve'
在运行类似的代码的时候出现了这样的问题,按理说这样的事情应该和版本问题是脱不了关系的,但是究竟是什么地方出了问题呢?
原因分析及解决
方法一、找到合适的版本
先求助chatgpt,给出了这样的答复:
这个错误表明在你尝试使用
sklearn.metrics.plot_roc_curve绘制 ROC 曲线时出现了问题,因为在你当前的 scikit-learn 版本中,plot_roc_curve方法可能不存在。这通常是由于 scikit-learn 版本过低所致。
plot_roc_curve是在 scikit-learn 0.22 版本中引入的。如果你的 scikit-learn 版本低于该版本,就会出现此错误。

2839

被折叠的 条评论
为什么被折叠?



