sklearn.model_selection.GridSearchCV 如何检索所有 .best_params_

sklearn.model_selection.GridSearchCV how to retrieve all .best_params_

svc_pipeline = make_pipeline(
    StandardScaler(), SVC(random_state=1)
)
pipe_svc_bag = BaggingClassifier(
    base_estimator=svc_pipeline, n_estimators=10, bootstrap=True, random_state=1
)
param_grid = [
    {'base_estimator__svc__kernel': ['linear', 'poly', 'rbf', 'sigmoid']},
    {'base_estimator__svc__C': np.linspace(0.1, 2, 20)}
]
svc_bag_grid = GridSearchCV(
    estimator=pipe_svc_bag, param_grid=param_grid, cv=10
)
svc_bag_grid.fit(X, y)
print(svc_bag_grid.best_params_)

我在param_grid里指定了两个参数,调用svc_bag_grid.best_params_时只有returns{'base_estimator__svc__kernel': 'linear'},但我也想知道[=的最佳C值16=] 我在里面指定 param_grid.

param_grid需要是一个字典,每个参数都是里面的一个元素。而不是你拥有的字典列表...

param_grid = {'base_estimator__svc__C': np.linspace(0.1, 2, 20),
    'base_estimator__svc__kernel': ['linear', 'poly', 'rbf', 'sigmoid']}