转轮3 发表于 2019-12-4 09:28 
请问是改为:kf = KFold(y,n_splits=5,shuffle=True)吗,我这么做的话还是会报错
from sklearn.model_selection import KFold
from sklearn.model_selection import train_test_split
def run_cv(X,y,clf_class,**kwargs):
kf=KFold(5,shuffle=True)
y_pred=y.copy()
for train_index,test_index in kf.split(X):
X_train,X_test=X[train_index],X[test_index]
y_train=y[train_index]
clf=clf_class(**kwargs)
clf.fit(X_train,y_train)
y_pred[test_index]=clf.predict(X_test)
return y_pred