StratifiedKFold不会出错
import numpy as np
from sklearn import model_selection
from sklearn.model_selection import KFold,StratifiedKFold
x = np.array(list(range(10)))
y = np.array(list([0]*5+[1]*5))
# kfold = KFold(n_splits=5,shuffle=False)
# for train, test in kfold.split(x,y):
# print("%s %s %s %s" % (x[train], y[train],x[test],y[test]))
kfold = StratifiedKFold(n_splits=5, shuffle=False)
for train, test in kfold.split(x,y):
print("%s %s %s %s" % (x[train], y[train],x[test],y[test]))
StratifiedKFold会出错
import numpy as np
from sklearn import model_selection
from sklearn.model_selection import KFold,StratifiedKFold
x = np.array(list(range(10)))
y = np.array(list(range(10)))
# y = np.array(list([0]*5+[1]*5))
# kfold = KFold(n_splits=5,shuffle=False)
# for train, test in kfold.split(x,y):
# print("%s %s %s %s" % (x[train], y[train],x[test],y[test]))
kfold = StratifiedKFold(n_splits=5, shuffle=False)
for train, test in kfold.split(x,y):
print("%s %s %s %s" % (x[train], y[train],x[test],y[test]))