解决如下出错:DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19.
背景:在Spyder中写几行脚本,目的是应用sklearn自带的svm(支持向量机)算法,来对其自带的digits(手写体数字)数据集进行分类,过程包括训练阶段和预测阶段。将手写体数字数据的特征数据data、标签数据target的倒数第一个样本点作为测试样本点,其余作为训练样本。
问题描述:出现DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample. DeprecationWarning)
问题代码如下:

修正方式:
第一种:第17行改为a = clf.predict([digits.data[-1]]),即在待测样本数据上多套一个'[ ]'(方括号);

第二种:对17行中的待测样本数据作reshape((1,-1)).

总结:
我们可以来看一下一开始的错误出在哪里,用下面代码打印出三段代码中的clf.predict(*)中的输入数据:

得到如下,三者的数据内容都一致,都含有64个数字,但是其形式不一样。

再由下述可以看出第一种测试数据的形式为1维、大小64的numpy.ndarray数据类型,第二种是一个list(列表,容器),里面装了一个2维、大小1x64的numpy.ndarray的数据,第三种是2维、大小1x64的numpy.ndarray数据类型。由此可以总结出,传给clf.predict()的数据应当为2维数组,因为显然每一个样本都有64个特征,应当将其作为一个整体传入clf.predict(),第一种测试数据传入的顶多就一个数字0.(第一个元素),显然不能预测出结果来(最后一句话是个人的理解,可能不对)。


参考网址:
1.https://www.cnblogs.com/okokok/p/6004871.html
解决如下出错:DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19.的更多相关文章
- 解决: DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19
错误信息:C:\Python27\lib\site-packages\sklearn\utils\validation.py:395: DeprecationWarning: Passing 1d a ...
- 在mvc返回JSON时出错:序列化类型为“System.Data.Entity.DynamicProxies.Photos....这个会的对象时检测到循环引用 的解决办法
在MVC中返回JSON时出错,序列化类型为“System.Data.Entity.DynamicProxies.Photos....这个会的对象时检测到循环引用. public ActionResul ...
- 解决:启动项目报错 java.lang.UnsatisfiedLinkError: D:\Java\apache-tomcat-8.0.17\bin\tcnative-1.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
启动项目报错如下: java.lang.UnsatisfiedLinkError: D:\Java\apache-tomcat-8.0.17\bin\tcnative-1.dll: Can't loa ...
- 完美解决 scipy.misc.imread 报错 TypeError: Image data cannot be converted to float
File "/home/harrison/anaconda3/lib/python3.7/site-packages/matplotlib/image.py", line 634, ...
- 解决composer出错的原因
1.执行了php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" 2.出 ...
- 解决Navicat 出错:1130-host . is not allowed to connect to this MySql server,MySQL
1. 改表法. 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入MySQL后,更改 "mysql" 数据库里的 " ...
- centos中python2替换为python3,并解决yum出错
这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...
- [未解决]报错:DeprecationWarning: decodestring() is a deprecated alias since Python 3.1, use decodebytes()
DeprecationWarning: decodestring() is a deprecated alias since Python 3.1, use decodebytes()
- 解决网站出错后 跳转 友好页面 的 asp .net 配置
<system.webServer> <httpErrors errorMode="DetailedLocalOnly"> <remove statu ...
随机推荐
- Java Web 常用在线api汇总(不定时更新)
1.Hibernate API Documentation (3.2.2.ga) http://www.hibernate.org/hib_docs/v3/api/ 2.Spring Framewor ...
- mongodb 3.4 学习 (二)命令
# 使用或切换数据库 use <database name> # 显示所有数据库 show dbs # 显示所有collection show collections # 显示所有user ...
- zip4j之加压解压
最近看同事搞个文件打包,搞了大半天,还是有问题!嗨~~ 网上明明有现成的,偏偏要自己写! 下面是基于zip4j实现加压解决的简单工具类 package com.learcher.zip; import ...
- libxml
/** * section: Tree * synopsis: Navigates a tree to print element names * purpose: Parse a file to a ...
- SpringCloud实战3-Hystrix请求熔断与服务降级
我们知道大量请求会阻塞在Tomcat服务器上,影响其它整个服务.在复杂的分布式架构的应用程序有很多的依赖,都会不可避免地在某些时候失败.高并发的依赖失败时如果没有隔离措施,当前应用服务就有被拖垮的风险 ...
- bzoj 1597 斜率DP
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 5115 Solved: 1897[Submit] ...
- css盒模型-BFC
BFC(边距重叠解决方案) 1.BFC的基本概念:块级格式化上下文 2.BFC的原理(说白了就是BFC的渲染规则): 这个规则是什么呢?我觉得大家能说出4点就够了 第一个就是BFC可以解决这个元素的垂 ...
- 小练习——关于循环条件---for
1.打印100个“非常”的句子 static void Main(string[] args) { //打印20个“非常" Console.WriteLine("打印100个非常& ...
- [19/03/24-星期日] 容器_Collection(集合、容器)之List(表,有顺序可重复)
一. 概念&方法 Collection 表示一组对象,它是集中.收集的意思.Collection接口的两个子接口是List.Set接口. 由于List.Set是Collection的子接口,意 ...
- Visual Studio 2010 RDLC 报表简单使用
原文:Visual Studio 2010 RDLC 报表简单使用 RDLC(Report Definition Language Client-side Processing)是Visual Stu ...