交叉验证问题 [英] Issue with Cross Validation
本文介绍了交叉验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用留一法交叉验证。但是我遇到了以下错误:
I want to use leave one out cross validation. But i am getting below error:
AttributeError Traceback (most recent call last)
<ipython-input-19-f15f1e522706> in <module>()
3 loo = LeaveOneOut(num_of_examples)
4 #loo.get_n_splits(X_train_std)
----> 5 for train, test in loo.split(X_train_std):
6 print("%s %s" % (train, test))
AttributeError: LeaveOneOut对象没有属性 split
AttributeError: 'LeaveOneOut' object has no attribute 'split'
详细代码如下:
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test =
train_test_split(X, y, test_size=0.3, random_state=0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)
from sklearn.cross_validation import LeaveOneOut
num_of_examples = len(X_train_std)
loo = LeaveOneOut(num_of_examples)
for train, test in loo.split(X_train_std):
print("%s %s" % (train, test))
推荐答案
使用
from sklearn.model_selection import train_test_split
而不是cross_validation,因为将cross_validation更改为model_selction
rather than cross_validation because cross_validation in changed into model_selction
这篇关于交叉验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文