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_
时,它只返回 {'base_estimator__svc__kernel': 'linear'}
,但我也想知道我在 param_grid
中为 SVC()
指定的最佳 C 值。
回答:
param_grid
需要是一个字典,每个参数是其中的一个元素。而不是像你那样的一系列字典…
param_grid = {'base_estimator__svc__C': np.linspace(0.1, 2, 20), 'base_estimator__svc__kernel': ['linear', 'poly', 'rbf', 'sigmoid']}