我正在使用以下代码进行准确度得分计算。为什么默认配置比 GridSearch 提供更好的结果?
默认配置
clf = svm.SVC(kernel='rbf', gamma='auto')
clf.fit(x_train, y_train.values.ravel())
y_train_pred = clf.predict(x_train)
y_test_pred = clf.predict(x_test)
print('Train set accuracy: '+'{}'.format(metrics.accuracy_score(y_train, y_train_pred)))
print('Test set accuracy: '+'{}'.format(metrics.accuracy_score(y_test, y_test_pred)))
训练集精度:0.861101243339254
测试集精度:0.8480113636363636
网格搜索配置
param_grid = {'C': (0.001, 0.01, 0.1, 1, 10),
'kernel': ('linear', 'poly', 'rbf', 'sigmoid'),
'class_weight': ('balanced', None),
'gamma' : ('scale', 'auto'),
'shrinking': (True, False)}
grid_search = GridSearchCV(svm.SVC(gamma='scale'), param_grid, cv=5)
grid_results = grid_search.fit(x_train, y_train.values.ravel())
print(grid_results.best_score_)
print(grid_results.best_estimator_)
print(grid_results.best_params_)
0.8373001776198934
SVC(C=1,cache_size=200,class_weight=None,coef0=0.0,decision_function_shape='ovr',degree=3,gamma='auto',kernel='rbf',max_iter=-1,probability=False, random_state=None, shrinking=True, tol=0.001, verbose=False)
{'C': 1, 'class_weight': None, 'gamma': 'auto', 'kernel': 'rbf', 'shrinking': True }