# HELP: http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.KFold.html
from sklearn.cross_validation import KFold
import numpy as np
# data
X = np.array([2.3,4.2,5.3,3.1,4.5,6.2])
y = np.array([34543,24432,85432,32543,75433,21124])
# build object
#kf = KFold(6, n_folds=2,shuffle=False,random_state=None) # not random selection
kf = KFold(6, n_folds=2,shuffle=True,random_state=None) # random selection
print(len(kf))
print(kf)
# create samples for training and test for each iteration
for train_index, test_index in kf:
print("indexes of samples for each iteration","TRAIN:", train_index, "TEST:", test_index)
# x points of samples (training, test) for each iteration
X_train, X_test = X[train_index], X[test_index]
# y points of samples (training, test) for each iteration
y_train, y_test = y[train_index], y[test_index]
# here include validation for each iteration
# here calculate the average error of n_folds iterations