背景:在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

2.https://stackoverflow.com/questions/43475439/python-deprecationwarning-passing-1d-arrays-as-data-is-deprecated-in-0-17-and-w

解决如下出错:DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19.的更多相关文章

  1. 解决: 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 ...

  2. 在mvc返回JSON时出错:序列化类型为“System.Data.Entity.DynamicProxies.Photos....这个会的对象时检测到循环引用 的解决办法

    在MVC中返回JSON时出错,序列化类型为“System.Data.Entity.DynamicProxies.Photos....这个会的对象时检测到循环引用. public ActionResul ...

  3. 解决:启动项目报错 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 ...

  4. 完美解决 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, ...

  5. 解决composer出错的原因

    1.执行了php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" 2.出 ...

  6. 解决Navicat 出错:1130-host . is not allowed to connect to this MySql server,MySQL

    1. 改表法. 可能是你的帐号不允许从远程登陆,只能在localhost.这个时候只要在localhost的那台电脑,登入MySQL后,更改 "mysql" 数据库里的 " ...

  7. centos中python2替换为python3,并解决yum出错

    这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...

  8. [未解决]报错:DeprecationWarning: decodestring() is a deprecated alias since Python 3.1, use decodebytes()

    DeprecationWarning: decodestring() is a deprecated alias since Python 3.1, use decodebytes()

  9. 解决网站出错后 跳转 友好页面 的 asp .net 配置

    <system.webServer> <httpErrors errorMode="DetailedLocalOnly"> <remove statu ...

随机推荐

  1. centos7部署ethereum私有链

    https://github.com/ethereum/go-ethereum/wiki http://book.8btc.com/books/6/ethereum/_book/public-chai ...

  2. java:反射机制

    Java反射机制及IoC原理:https://www.cnblogs.com/Eason-S/p/5851078.html Java中反射机制详解:https://www.cnblogs.com/wh ...

  3. SQL Server ->> CLR编程问题汇总

    1) CLR不支持C#类方法重载(Method Overload) 今天打算写个枚举目录的C# CLR存储过程,结果发现原来CLR不支持方法重载. Msg 6572, Level 16, State ...

  4. 【Spring实战】—— 4 Spring中bean的init和destroy方法讲解

    本篇文章主要介绍了在spring中通过配置init-method和destroy-method方法来实现Bean的初始化和销毁时附加的操作. 在java中,我们并不需要去管理内存或者变量,而在C或C+ ...

  5. JS支持可变参数(任意多个)

    <script type="text/javascript"> function abc(){ //js中有个变量arguments,可以访问所有传入的值 for(va ...

  6. May 27th 2017 Week 21st Saturday

    I learned the value of hard work by working hard. 只有真的努力了,才会知道努力的价值. I remember in the movie, The Da ...

  7. 2018.10.2 Eclipse中如何测地修改一个we项目步骤

    找到项目的web.xml文件 大概的路径如下: 修改xml文件中的display-name 节点的值 下一步就是切换工作目录 显示的效果 打开最后一个文件修改 接下来找到这个文件 是部署的时候用的 运 ...

  8. xml或其他附件下载到客户端

    //xml Document document=DocumentHelper.createDocument(); Element root=document.addElement("root ...

  9. 【洛谷P3853】 [TJOI2007]路标设置

    路标设置 题目链接 此题和跳石头很相似,都是二分答案,模拟判断是否可行 #include<iostream> #include<cstdio> using namespace ...

  10. 开发一个c#的数据库连接池

    c#操作数据库是一个经典,用习惯了以后真感觉不错,很简单的.现在很多关系数据库都支持c#.c#的ADO.NET规范都遵守. 对于一般的设置,ADO.NET都放在数据库连接字符串上.比如池化,连接超时等 ...