Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法

在使用Python的sklearn库时,发现sklearn的cross_validation不能使用,在pycharm上直接显示为被横线划掉。

运行程序:

import sklearn
...
X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y)

报错:

AttributeError: 'module' object has no attribute 'cross_validation'

这里尝试修改为:

from sklearn.cross_validation import train_test_split
X, Xt, y, yt = train_test_split(X, y)

发现不再报错,而是提示警告信息:

**DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.

"This module will be removed in 0.20.", DeprecationWarning) **

程序能够正常执行。

但是注意看提示信息,实际上是说cross_validation模块被弃用了,改为支持model_selection这个模块,因此,将程序改为:

from sklearn.model_selection import train_test_split
X, Xt, y, yt = train_test_split(X, y)

不再出现警告信息,一切正常。

Python提示AttributeError 或者DeprecationWarning: This module was deprecated解决方法的更多相关文章

  1. ImportError: No module named cv2 解决方法

    ImportError: No module named cv2 解决方法   import cv2时会出现这个问题 解决方法:将openCV安装目录里的python文件夹内的cv2.pyd复制到Py ...

  2. Sublime2编译Python程序EOFError:EOF when reading a line解决方法【转】

    在Sublime2中编译运行Python文件时,如果代码中包含用户输入的函数时(eg. raw_input()),Ctrl+b编译运行之后会提示以下错误: 解决方法:安装SublimeREPL打开Su ...

  3. Python3中使用HTMLTestRunner报No module named 'StringIO'解决方法

    今天在学习使用HTMLTestRunner生成测试报告时遇到一个报错,如图所示: 网上搜索了下“No module named 'StringIO'”解决方法,原来我用的是Python 3.X版本,而 ...

  4. pip 安装使用 ImportError: No module named setuptools 解决方法

    安装过程详见这篇博客: http://www.ttlsa.com/python/how-to-install-and-use-pip-ttlsa/ 安装后运行到:python setup.py ins ...

  5. VMware虚拟机提示“锁定文件失败 打不开磁盘”解决方法

    VMware虚拟机提示“锁定文件失败 打不开磁盘”解决方法 摘自: http://www.xitongcheng.com/jiaocheng/xtazjc_article_40299.html 发布时 ...

  6. python 提示 AttributeError: module 'json' has no attribute 'dumps'

    最近在学习python解析json的时候遇到问题, 提示 AttributeError: module 'json' has no attribute 'dumps' (模块没有dumps属性的意思) ...

  7. python程序在命令行执行提示ModuleNotFoundError: No module named 'XXX' 解决方法

    在ide中执行python程序,都已经在默认的项目路径中,所以直接执行是没有问题的.但是在cmd中执行程序,所在路径是python的搜索路径,如果涉及到import引用就会报类似ImportError ...

  8. Python ImportError: No module named 'requests'解决方法

    前言:最近在学习python,安装了python3.5的环境后,在网上下载了一个python文件运行的时候,提示ImportError: No module named 'requests'(找不到r ...

  9. Windows下运行python脚本报错“ImportError: No Module named ...”的解决方法

    之前遇到一个问题,在Pycharm或IPython之类的IDE上运行脚本正常,但是直接运行或cmd命令行运行的时候报了模块未能找到的错误--ImportError: No Module named . ...

随机推荐

  1. hdu 4348 To the moon (主席树 区间更新)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4348 题意: 4种操作: C l r c   区间[l,r]加c,时间+1 Q l r    询问当前时 ...

  2. poj2586 【贪心】

    Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for ...

  3. Java创建文件

    public class FileTest { public static void main(String[] args) throws IOException { File file = new ...

  4. Spring MVC 起步

    跟踪Spring MVC的请求 在请求离开浏览器时①,会带有用户所请求内容的信息,至少会包含请求的URL. 请求旅程的第一站是Spring的DispatcherServlet.与大多数基于Java的W ...

  5. Windows 10中设置自动登录

    步骤 使用WinKey+R打开运行,输入netplwiz. 在打开的用户账户对话框-用户选项卡-取消勾选要使用本计算机,用户必须输入用户名和密码(E). 点击应用按钮,在弹出的自动登录对话框中输入相关 ...

  6. cdn模式下vue的基本用法

    我们知道jq是简化了dom操作,而react和vue则是通过使用虚拟dom的方式,不需要频繁的更改ui界面,而是通过更改数据的方式来更新界面. 我们知道些jq插件时会在IFFE中传入jQuery,jQ ...

  7. Linux:打印(输出)所有的列(awk, $0)

    如果想输出所有的列的话,只需要$0这个函数,例如以下命令: awk '/rs16945916/ {print $0}' test.txt > allcol.txt rs16945916指的是打印 ...

  8. Error configuring application listener of

    最近在做spring+struts2+IbatIS的项目,昨天eclipse启动服务器正常,结果今天来了就总是报错,错误如下:严重: Error configuring application lis ...

  9. 源码研究:php变量

    一:php中的变量类型 1.标量类型:布尔型 bool,整型 int,浮点型 float,字符串型 string2.复杂类型:数组 array,对象 object3.特殊类型:NULL,资源 reso ...

  10. JavaScript中对象分类

    js的对象有三大类,内部对象(本地对象和内置对象).宿主对象和自定义对象 一.内部对象 1.本地对象,ECMAScript提供的需要实例化(new)才能使用的对象: Object.Function.A ...