【发布时间】:2020-04-25 15:22:58
【问题描述】:
我正在尝试使用 GridSearchCV 找出 SVC 模型中的最佳估算器,这是我的代码和输出
from sklearn import datasets
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
param_grid = {'C': [5e3,1e3, 1e4, 5e4, 1e5], 'gamma': [0.0005, 0.0001, 0.001, 0.005, 0.01, 0.1]}
clf = GridSearchCV(SVC(kernel='rbf', class_weight='balanced', probability=True), param_grid)
clf = clf.fit(emb_array, label)
print("Best estimator found by grid search:")
print(clf.best_estimator_)
输出
Best estimator found by grid search:
SVC(C=5000.0, cache_size=200, class_weight='balanced', coef0=0.0,
decision_function_shape='ovr', degree=3, gamma=0.0005, kernel='rbf',
max_iter=-1, probability=True, random_state=None, shrinking=True, tol=0.001,
verbose=False)
如果我将param_grid 更改为
param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5], 'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1]}
然后输出
Best estimator found by grid search:
SVC(C=1000.0, cache_size=200, class_weight='balanced', coef0=0.0,
decision_function_shape='ovr', degree=3, gamma=0.0001, kernel='rbf',
max_iter=-1, probability=True, random_state=None, shrinking=True, tol=0.001,
verbose=False)
如果它只将第一个参数作为best_estimator_ 最好,那么GridSearchCV 有什么用?
【问题讨论】:
标签: python scikit-learn grid-search svc