AttributeError: 'module' object has no attribute 'cross_validation'
2017-07-05 16:59
651 查看
請注意,本類僅僅是記錄開發過程中遇到對問題,可能會亂貼代碼,亂貼圖,亂貼報錯信息,不保證能解決問題,以及有優美的排版,後面有時間我會重新整理的。
報錯信息
在PyCharm中一跑
發現
去官網查了一下
多了
就可以通過了。後面
解決問題後的代碼
報錯信息
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-13a258632ba9> in <module>() 5 6 # Split into train and test ----> 7 X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y) 8 9 # Visualize sample of the data AttributeError: 'module' object has no attribute 'cross_validation'
在PyCharm中一跑
Traceback (most recent call last): File "/home/pikachu/PycharmProjects/2017_shixun/study_brewing_logreg.py", line 34, in <module> X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y) AttributeError: 'module' object has no attribute 'cross_validation' Process finished with exit code 1
發現
cross_validation有刪除線
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. less... (Ctrl+F1) This inspection highlights usages of Python functions, classes or methods which are marked as deprecated (which raise a DeprecationWarning or a PendingDeprecationWarning).
去官網查了一下
多了
from sklearn.model_selection import train_test_split
sklearn.cross_validation.train_test_split改爲類
train_test_split
就可以通過了。後面
pd.plotting.scatter_matrix類似。
解決問題後的代碼
#!/usr/bin/env python # -*- coding:utf-8 -*- # sudo pip install sklearn import numpy as np import matplotlib.pyplot as plt # %matplotlib inline import os os.chdir('..') import sys sys.path.insert(0, './python') import caffe import os import h5py import shutil import tempfile import sklearn import sklearn.datasets import sklearn.linear_model import pandas as pd X, y = sklearn.datasets.make_classification( n_samples=10000, n_features=4, n_redundant=0, n_informative=2, n_clusters_per_class=2, hypercube=False, random_state=0 ) from sklearn.model_selection import train_test_split # Split into train and test # X, Xt, y, yt = sklearn.cross_validation.train_test_split(X, y) X, Xt, y, yt = train_test_split(X, y) # Visualize sample of the data ind = np.random.permutation(X.shape[0])[:1000] df = pd.DataFrame(X[ind]) _ = pd.plotting.scatter_matrix(df, figsize=(9, 9), diagonal='kde', marker='o', s=40, alpha=.4, c=y[ind])
相关文章推荐
- 解决问题 AttributeError: 'module' object has no attribute 'face_recognition_model_v1'
- AttributeError: 'module' object has no attribute 'text_format'
- AttributeError: ‘module’ object has no attribute’ 问题
- 使用旧版本tensorflow出现了negative等报错的问题,AttributeError: 'module' object has no attribute 'xxx'"
- AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'
- AttributeError: ‘module’ object has no attribute ‘load_dotenv
- AttributeError: 'module' object has no attribute '_base' 可行解决办法
- AttributeError: 'module' object has no attribute 'best_partition'
- AttributeError: 'module' object has no attribute 'AF_INET'
- web.py 启动时候出现AttributeError: 'module' object has no attribute 'inet_pton'错误
- AttributeError: 'classmethod' object has no attribute '__module__'
- AttributeError: 'module' object has no attribute 'SSL_ST_INIT' 解决办法
- AttributeError: 'module' object has no attribute 'LabelMap'
- AttributeError: 'module' object has no attribute 'randint'
- AttributeError: ‘module’ object has no attribute’xxx 问题解决
- AttributeError: 'module' object has no attribute 的解决方法
- AttributeError: 'module' object has no attribute 的解决方法
- 【TensorFlow问题】AttributeError:'module' object has no attribute 'mul'
- AttributeError: 'module' object has no attribute '_base' 可行解决办法
- AttributeError: 'module' object has no attribute 'text_format'