本笔记来源于B站Up主: 有Li 的影像组学系列教学视频
本节(13)主要介绍: p次k折交叉验证
# k折交叉验证
# kf = KFold(10) #10折1次验证
# p次k折交叉验证,更普适
rkf = RepeatedKFold(n_splits = 3, n_repeats = 2)
for train_index, test_index in rkf.split(X):
X_train = X.iloc[train_index]
X_test = X.iloc[test_index]
y_train = y.iloc[train_index]
y_test = y.iloc[test_index]
model_svm = svm.SVC(kernel = 'rbf', C = C, gamma = gamma, probability = True).fit(X_train,y_train)
score_svm = model_svm.score(X_test,y_test)
print(score_svm)
# method 2
score_svm = cross_val_score(model_svm, X,y,cv = 3,scoring = 'accuracy') #没有混序功能
print(score_svm)