svc = GridSearchCV(SVC(), param_grid,scoring='f1_macro', verbose=1000)
svc.fit(X_train, y_train)
predictions = svc.predict(X_test)
我多次运行此代码,但结果是相同的。GridSearchCV 是否选择相同的交叉验证集(不是随机选择)?
svc = GridSearchCV(SVC(), param_grid,scoring='f1_macro', verbose=1000)
svc.fit(X_train, y_train)
predictions = svc.predict(X_test)
我多次运行此代码,但结果是相同的。GridSearchCV 是否选择相同的交叉验证集(不是随机选择)?
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)