sklearn里计算roc_auc_score,报错ValueError: bad input shape
用sklearn的DecisionTreeClassifer训练模型,然后用roc_auc_score计算模型的auc。代码如下
clf = DecisionTreeClassifier(criterion='gini', max_depth=6, min_samples_split=10, min_samples_leaf=2)
clf.fit(X_train, y_train)
y_pred = clf.predict_proba(X_test)
roc_auc = roc_auc_score(y_test, y_pred)
报错信息如下
/Users/wgg/anaconda/lib/python2.7/site-packages/sklearn/metrics/ranking.pyc in _binary_clf_curve(y_true, y_score, pos_label, sample_weight)
297 check_consistent_length(y_true, y_score)
298 y_true = column_or_1d(y_true)
--> 299 y_score = column_or_1d(y_score)
300 assert_all_finite(y_true)
301 assert_all_finite(y_score) /Users/wgg/anaconda/lib/python2.7/site-packages/sklearn/utils/validation.pyc in column_or_1d(y, warn)
560 return np.ravel(y)
561
--> 562 raise ValueError("bad input shape {0}".format(shape))
563
564 ValueError: bad input shape (900, 2)
目测是你的y_pred出了问题,你的y_pred是(900, 2)的array,也就是有两列。
因为predict_proba返回的是两列。predict_proba的用法参考这里。
简而言之,你上面的代码改成这样就可以了。
y_pred = clf.predict_proba(X_test)[:, 1]
roc_auc = roc_auc_score(y_test, y_pred)
原文:http://sofasofa.io/forum_main_post.php?postid=1001678
sklearn里计算roc_auc_score,报错ValueError: bad input shape的更多相关文章
- 标记编码报错ValueError: bad input shape ()
<Python机器学习经典实例>2.9小节中,想自己动手实践汽车特征评估质量,所以需要对数据进行预处理,其中代码有把字符串标记编码为对应的数字,如下代码 input_data = ['vh ...
- keras 报错 ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("embedding_1/random_uniform:0", shape=(5001, 128), dtype=float32)'
在服务器上训练并保存模型,复制到本地之后load_model()报错: ValueError: Tensor conversion requested dtype int32 for Tensor w ...
- matplotlib.pyplot import报错: ValueError: _getfullpathname: embedded null character in path
Environment: Windows 10, Anaconda 3.6 matplotlib 2.0 import matplotlib.pyplot 报错: ValueError: _getfu ...
- 安装 r 里的 igraph 报错
转载来源:http://genek.tv/article/40 1186 0 0 安装 r 里的 igraph 报错: foreign-graphml.c: In function ‘igraph_w ...
- dbfread报错ValueError错误解决方法
问题 我在用dbfread处理.dbf数据的时候出现了报错 ValueError("could not convert string to float: b'.'",) 然后查找. ...
- moviepy音视频剪辑VideoClip类fl_image方法image_func报错ValueError: assignment destination is read-only解决办法
☞ ░ 前往老猿Python博文目录 ░ moviepy音视频剪辑模块的视频剪辑基类VideoClip的fl_image方法用于进行对剪辑帧数据进行变换. 调用语法:fl_image(self, im ...
- Linux部署Django:报错 nohup: ignoring input and appending output to ‘nohup.out’
一.部署 Django 到远程 Linux 服务器 利用 xshell 通过 ssh 连接到 Linux服务器,常规的启动命令是 python3 manage.py runserver 但是,关闭 x ...
- tensorflow-TFRecord报错ValueError: Protocol message Feature has no "feature" field.
编写代码用TFRecord数据结构存储数据集信息是报错:ValueError: Protocol message Feature has no "feature" field.或和 ...
- datetime.strptime格式转换报错ValueError
今天遇到一个报错:ValueError: time data '2018-10-10(Wednesday) AM0:50' does not match format '%Y-%m-%d(%A) %p ...
随机推荐
- 【年度盘点】最受欢迎的5大Java练习项目
5. SSM + easyUI 搭建简易的人事管理系统 当前学习采用 SSM + easyUI 来开发一个比较简易的人事管理系统,让大家能够通过实际项目掌握 SSM 项目的开发.项目当前学习人数:16 ...
- awk初级教程
参考:sed & awk 概述 sed & awk指令组成 与sed区别 尽管awk指令与sed指令的结构相同,都由模式和过程两部分组成,但过程本身有很大不同. awk看上去不像编辑器 ...
- Nginx服务优化及优化深入(配置网页缓存时间、日志切割、防盗链等等)
原文:https://blog.51cto.com/11134648/2134389 默认的Nginx安装参数只能提供最基本的服务,还需要调整如网页缓存时间.连接超时.网页压缩等相应参数,才能发挥出服 ...
- Laravel 队列的简单使用例子
场景: 在一个a系统中注册一个用户时,发送请求到b系统中也注册一个相同信息的账号,考虑到网络有可能错误的原因,所以使用队列去处理 1.修改根目录 .env 文件的QUEUE_CONNECTION字段配 ...
- Wide & Deep Learning for Recommender Systems
Wide & Deep Learning for Recommender Systems
- Codeforces Round #609 (Div. 2) C. Long Beautiful Integer
链接: https://codeforces.com/contest/1269/problem/C 题意: You are given an integer x of n digits a1,a2,- ...
- 洛谷P1972 HH的项链【树状数组】
题目:https://www.luogu.org/problemnew/show/P1972 题意:给定一个长度为n的序列,数字表示珠子的种类.m次查询每次询问给定区间内珠子的种类数. 思路:可以说是 ...
- QProgressBar 样式
setStyleSheet( "QProgressBar{border:1px solid #FFFFFF;" "height:30;" "backg ...
- OTFS Research Notes
△f = f·v·cosθ/c,f表示载波频率,5G/B5G朝着毫米波等高频段方向发展,因此多普勒拓展的影响将更显著.此外,Masssive MIMO的现有规模已达256维度,并将朝着上千的规模发展. ...
- MongoDB 分片管理(四)数据均衡 -- 特大快
1.1 特大快形成 如果用date字段作为片键,集合中date是一个日期字符串,如:year/month/day,也就是说,mongoDB一天创建一个块.因块内所有文档的片键一样,因此这些块是不可拆分 ...