クロス検証cross validation
1271 ワード
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn import datasets
from sklearn import svm
iris=datasets.load_iris()
X_train,X_test,y_train,y_test = train_test_split(iris.data, iris.target, test_size = 0.4, random_state=0)
from sklearn.model_selection import KFold
kf = KFold(n_splits=2)
for train,test in kf.split(X):
from sklearn.cross_validation import StratifiedKFold
cv = StratifiedKFold(y, n_folds=6)
for i,(train,test) in enumerate(cv):
または、
from sklearn.model_selection import StratifiedKFold
skf = StratifiedKFold(n_splits=3)
for train,test in skf.split(X,y):
その他の関数の具体的な使用については、参照してください.http://scikit-learn.org/stable/modules/cross_validation.html