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. POJ3176-基础DP

    很基础的dp题.有一头奶牛想接尽量多的苹果,有w此移动机会. dp[i][w] = max(dp[i-1][w+1] + 能否吃到苹果 ,dp[i-1][w] + 能否吃到苹果)  //从上一分钟是否 ...

  2. day9 集合基础命令

    集合的创建 s = set("hello") print(s) s = set({","alex","sb"}) print(s) ...

  3. 让一个继承unittest.TestCase的类下的setUp和tearDown只执行一次

    知道unittest单元测试框架的朋友应该都知道, 执行继承了unittest.TestCase的类下每个test开头的方法(就是用例)时,都会执行setUp和tearDown,如下面的例子所示: i ...

  4. virtualenv 包管理

    创建虚拟环境: 1) pip install virtualenv 2) virtualenv  DemoEnv(虚拟环境名) 3) 此处windows和linux不同系统下的文件结构略有不同 lin ...

  5. 【codeforces 103E】 Buying Sets

    http://codeforces.com/problemset/problem/103/E (题目链接) 题意 给出$n$个数,每个数与一个集合相关联.从其中选出最小的若干个数,选出的数的个数与这些 ...

  6. CF815D Karen and Cards

    CF815D Karen and Cards 固定一维c,然后(a,b)看成坐标,矩形区域求交 1.Segment tree Beats! 2.改成不合法的区域就是求并,c反向枚举,区域只增不减且完全 ...

  7. A1048. Find Coins

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  8. 【POJ3090】Visible Lattice Points

    题目大意:求 \[\sum\limits_{i=2}^n\phi(i)\] 题解:利用与埃筛类似的操作,可在 \(O(nlogn)\) 时间求出结果. 代码如下 #include <cstdio ...

  9. 【LOJ#6278】数列分块2

    题目大意:分块维护一个有 n 个数字的序列,有两种操作:区间加,区间查询小于某个数的元素个数.n <= 50000 预处理阶段:处理出块内元素的相对大小顺序(排序),时间复杂度为 \(O(nlo ...

  10. 解决MATLAB出现"??? Undefined function or variable 'x'."的问题,一个等号引发的大战

    最近写了一段代码,一直弹出“??? Undefined function or variable 'x'.”这个错误.仔细检查了一下,发现是赋值的问题.比如下面两段代码 h=1 h=x h=1表示的是 ...