3
svc = GridSearchCV(SVC(), param_grid,scoring='f1_macro', verbose=1000)
svc.fit(X_train, y_train)
predictions = svc.predict(X_test)

我多次运行此代码,但结果是相同的。GridSearchCV 是否选择相同的交叉验证集(不是随机选择)?

4

1 回答 1

5

GridSearchCV默认情况下使用KFold交叉验证器,并且默认情况下KFold不打乱数据。要启用洗牌,您必须这样做

from sklearn.model_selection import KFold

cross_validator = KFold(shuffle=True)
svc = GridSearchCV(SVC(), param_grid, scoring='f1_macro', 
                   verbose=1000, cv=cross_validator)
svc.fit(X_train, y_train)
predictions = svc.predict(X_test)
于 2019-04-17T09:29:58.647 回答