您的位置:首页 > 移动开发 > Objective-C

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

2017-07-05 16:59 651 查看
請注意,本類僅僅是記錄開發過程中遇到對問題,可能會亂貼代碼,亂貼圖,亂貼報錯信息,不保證能解決問題,以及有優美的排版,後面有時間我會重新整理的。

報錯信息

---------------------------------------------------------------------------
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])
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐