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. MT【35】用复数得到的两组恒等式

    特别的,当$r\rightarrow1^{-}$时有以下两个恒等式: 第二个恒等式有关的自主招生试题参考博文MT[31]傅里叶级数为背景的三角求和 评:利用两种展开形式得到一些恒等式是复数里经常出现的 ...

  2. 51nod 1061 最复杂的数V2

    题目链接 51nod 1061 题面简述 求\([1, n]\)中约数个数最多的数. \(n \le 10^{200}\) 题解 首先,答案一定是一个反素数. 什么是反素数? 一个正整数\(x\)是反 ...

  3. 【转】嵌入式系统 Boot Loader 技术内幕,带你完全了解Boot Loader

    在专用的嵌入式板子运行 GNU/Linux 系统已经变得越来越流行.一个嵌入式 Linux 系统从软件的角度看通常可以分为四个层次: 1. 引导加载程序.包括固化在固件(firmware)中的 boo ...

  4. job.yml

    job.yml apiVersion: batch/v1kind: Jobmetadata: name: myjobspec: completions: 6 parallelism: 2 templa ...

  5. des加密解密JAVA与.NET互通实例

    JAVA版本 import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFacto ...

  6. R语言:多个因变量时,如何在plot函数中画多条曲线(plot,points,lines,legend函数)

    最近阅读一篇文献<Regional and individual variations in the function of the human eccrine sweat gland>, ...

  7. 2156: 中南大学2018年ACM暑期集训前期训练题集(入门题) D: 机器人的指令

    不要用gets!不要用gets!不要用gets! 不要用gets!不要用gets!不要用gets! 不要用gets!不要用gets!不要用gets! 不要用gets!不要用gets!不要用gets! ...

  8. HikariCP和spring-boot-devtools了解

    HikariCP的学习: 转:https://blog.csdn.net/clementad/article/details/46928621 spring data devtool的学习: 转:ht ...

  9. pthread_cleanup_push()/pthread_cleanup_pop()的详解

    一般来说,Posix的线程终止有两种情况:正常终止和非正常终止.线程主动调用pthread_exit()或者从线程函数中return都将使线程正常退出,这是可预见的退出方式:非正常终止是线程在其他线程 ...

  10. 20145215《网络对抗》Exp7 网络欺诈技术防范

    20145215<网络对抗>Exp7 网络欺诈技术防范 基础问题回答 通常在什么场景下容易受到DNS spoof攻击? 在同一局域网下比较容易受到DNS spoof攻击,攻击者可以冒充域名 ...