"AttributeError: type object 'RocCurveDisplay' has no attribute 'from_predictions' ".

目录

"AttributeError: type object 'RocCurveDisplay' has no attribute 'from_predictions' ".

问题:

解决:

完整错误:


问题:

使用sklearn中的RocCurveDisplay函数from_predictions发生问题、因为版本低的问题。

import numpy as npfrom sklearn import datasetsimport matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.metrics import RocCurveDisplay
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X, y = make_classification(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
clf = SVC(random_state=0).fit(X_train, y_train)
y_pred = clf.decision_function(X_test)
RocCurveDisplay.from_predictions(y_test, y_pred)plt.show()

解决:

版本更新一下、因为sklearn的版本低的缘故,需要升级。

scikit-learn 1.0之后才提供了from_predictions这些函数、类;

pip install --upgrade scikit-learn
import matplotlib.pyplot as plt
from sklearn.datasets import make_classification
from sklearn.metrics import RocCurveDisplay
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
X, y = make_classification(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
clf = SVC(random_state=0).fit(X_train, y_train)
y_pred = clf.decision_function(X_test)
RocCurveDisplay.from_predictions(y_test, y_pred)plt.show()

完整错误:

"AttributeError: type object 'RocCurveDisplay' has no attribute 'from_from_estimator' ".

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-c15b1ea4b93e> in <module>32 for i, (train, test) in enumerate(cv.split(X, y)):33     classifier.fit(X[train], y[train])
---> 34     viz = RocCurveDisplay.from_estimator(35         classifier,36         X[test],AttributeError: type object 'RocCurveDisplay' has no attribute 'from_estimator'

Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有比其他语言更有特色语法结构。

Python 是一种解释型语言: 这意味着开发过程中没有了编译这个环节。类似于PHP和Perl语言。

Python 是交互式语言: 这意味着,您可以在一个 Python 提示符 >>> 后直接执行代码。

Python 是面向对象语言: 这意味着Python支持面向对象的风格或代码封装在对象的编程技术。

Python 是初学者的语言:Python 对初级程序员而言,是一种伟大的语言,它支持广泛的应用程序开发,从简单的文字处理到 WWW 浏览器再到游戏。

1.易于学习:Python有相对较少的关键字,结构简单,和一个明确定义的语法,学习起来更加简单。

2.易于阅读:Python代码定义的更清晰。

3.易于维护:Python的成功在于它的源代码是相当容易维护的。

4.一个广泛的标准库:Python的最大的优势之一是丰富的库,跨平台的,在UNIX,Windows和Macintosh兼容很好。

5.互动模式:互动模式的支持,您可以从终端输入执行代码并获得结果的语言,互动的测试和调试代码片断。

6.可移植:基于其开放源代码的特性,Python已经被移植(也就是使其工作)到许多平台。

7.可扩展:如果你需要一段运行很快的关键代码,或者是想要编写一些不愿开放的算法,你可以使用C或C++完成那部分程序,然后从你的Python程序中调用。

8.数据库:Python提供所有主要的商业数据库的接口。

9.GUI编程:Python支持GUI可以创建和移植到许多系统调用。

10.可嵌入: 你可以将Python嵌入到C/C++程序,让你的程序的用户获得"脚本化"的能力。

参考:python - Error message with sklearn function " 'RocCurveDisplay' has no attribute 'from_predictions' " - Stack Overflow

参考:Receiver Operating Characteristic (ROC) with cross validation — scikit-learn 1.1.2 documentation

“AttributeError: type object ‘RocCurveDisplay‘ has no attribute ‘from_predictions‘ “.相关推荐

  1. 关于AttributeError: type object ‘XXX‘ has no attribute ‘XXX‘的问题

    关于AttributeError: type object 'XXXXXX' has no attribute 'name'的报错的原因,先运行运行一段代码 例如: class Person(obje ...

  2. python 提示错误AttributeError: type object 'str' has no attribute '_name_'

    在做<Machine Learning in Action>书中的第三章绘制树形图时遇到了这个问题AttributeError: type object 'str' has no attr ...

  3. AttributeError: type object ‘Image‘ has no attribute ‘open‘

    AttributeError: type object 'Image' has no attribute 'open' 原因分析:Image调用顺序出错,因为第一行的from PIL import I ...

  4. unittest-ddt报错AttributeError: type object ‘forTestDDT‘ has no attribute ‘test_2‘

    unittest 添加多个ddt数据驱动后,报错: FAILED (errors=1)Error Traceback (most recent call last):File "D:\Ana ...

  5. ubuntun 16.04 AttributeError: type object 'Callable' has no attribute '_abc_registry'

    ubuntun 16.04 python 升级到3.7遇到各种坑 其中在openvino 跑模型时遇到以下错误: root@magicdepth-OptiPlex-7010:/opt/intel/op ...

  6. AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘

    错误描述: Traceback (most recent call last):File "D:\OCR\DBNet.pytorch-master\tools\predict.py" ...

  7. 解决gensim报错AttributeError: type object ‘Word2Vec‘ has no attribute ‘load_word2vec_format‘

    解决方法 将报错的 from gensim.models import Word2Vecmodel = Word2Vec.load_word2vec_format('test.bin.gz', bin ...

  8. AttributeError:type object ‘TFLiteConverterV2 ‘has no attribute ‘form_keras_model_file ‘

    在Tensor Flow2.0以上加载keras模型文件使用load_model keras_model = tf_keras_models.load_model("xx.h5") ...

  9. python object has no attribute_如何修复python中的“AttributeError:type object has no attribute”?...

    您的代码引发此异常: AttributeError: type object 'Meeting' has no attribute 'datetime' 在这一行: meeting_start = M ...

最新文章

  1. SQL Server 数据库文件 4 点注意
  2. 最强轻量级目标检测yolo fastest
  3. 电子科技大学通信原理视频教程 瓦特芯收藏
  4. Fast RCNN 训练自己数据集 (1编译配置)
  5. js - 浅拷贝和深拷贝
  6. Promise解决多个异步Ajax请求导致的代码嵌套问题(完美解决方案)
  7. 比较默认对象和默认约束的异同_UE4对象类类型引用和类默认对象(Class Default Object,简称CDO)...
  8. windows截图快捷方式
  9. 第二章 爬取案例-链家租房数据获取 2021-09-16
  10. 微信小程序(组件:路由、表单、媒体、自定义组件,插槽、组件通讯、侦听器、生命周期)
  11. 浅谈这半年的实习感想
  12. Java正则表达式 - Matcher
  13. Mixly数码管TM1637时钟实验
  14. android bitmap转图片_这是一份面向Android开发者的复习指南
  15. 【面试题】闭包是什么?this 到底指向谁?
  16. 明渠如何快速估算水流量(明渠流量计算)
  17. 电信4g网速测试软件,移动联通电信三大运营商4G网速测试,仅供非专业人士参考...
  18. 31.最特殊的快捷键 Alt + Enter 介绍(新用户必看)
  19. 驾驶证识别/驾驶证OCR详解
  20. 一条sql是怎么执行的

热门文章

  1. 购物车及商品php代码_php购物车代码_php网上商城购物车代码一例
  2. UCAS - AI学院 - 计算机视觉专项课 - 第1讲 - 课程笔记
  3. 前沿科技探究DeepSQL:库内AI算法
  4. 可持续5G环境下基于机器学习的网络分片框架
  5. 博彩黑链应急响应学习
  6. 数据库——数据操作——单表查询(9)
  7. shell脚本修改服务器时间
  8. wx.requestSubscribeMessage微信小程序订阅消息总结
  9. 央视各种直播失误集锦
  10. 什么是SQL执行计划