1 回答

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個贊
StratifiedKFold已搬進(jìn)model_selection. 所以你應(yīng)該這樣做:
from sklearn.model_selection import StratifiedKFold
def stratified_cv(X, y, clf_class, shuffle=True, n_folds=10, **kwargs):
stratified_k_fold = StratifiedKFold(n_splits=n_folds, shuffle=shuffle)
y_pred = y.copy()
# ii -> train
# jj -> test indices
for ii, jj in stratified_k_fold.split(X,y):
X_train, X_test = X[ii], X[jj]
y_train = y[ii]
clf = clf_class(**kwargs)
clf.fit(X_train,y_train)
y_pred[jj] = clf.predict(X_test)
return y_pred
添加回答
舉報(bào)