管道中的 Adaboost 与 Gridsearch SKLEARN

Adaboost in Pipeline with Gridsearch SKLEARN

我想使用带有 LinearSVC 的 AdaBoostClassifier 作为基础估计器。我想对 LinearSVC 中的一些参数进行网格搜索。我还必须缩放我的功能。

p_grid = {'base_estimator__C': np.logspace(-5, 3, 10)}
n_splits = 5
inner_cv = StratifiedKFold(n_splits=n_splits,
                     shuffle=True, random_state=5)
SVC_Kernel=LinearSVC(multi_class ='crammer_singer',tol=10e-3,max_iter=10000,class_weight='balanced')
ABC = AdaBoostClassifier(base_estimator=SVC_Kernel,n_estimators=600,learning_rate=1.5,algorithm="SAMME")


for train_index, test_index in kk.split(input):


    X_train, X_test = input[train_index], input[test_index]
    y_train, y_test = target[train_index], target[test_index]


    pipe_SVC = Pipeline([('scaler',  RobustScaler()),('AdaBoostClassifier', ABC)])  

    clfSearch = GridSearchCV(estimator=pipe_SVC, param_grid=p_grid,
                             cv=inner_cv, scoring='f1_macro', iid=False, n_jobs=-1) 
    clfSearch.fit(X_train, y_train)

出现以下错误:

ValueError: Invalid parameter base_estimator for estimator Pipeline(memory=None,
         steps=[('scaler',
                 RobustScaler(copy=True, quantile_range=(25.0, 75.0),
                              with_centering=True, with_scaling=True)),
                ('AdaBoostClassifier',
                 AdaBoostClassifier(algorithm='SAMME',
                                    base_estimator=LinearSVC(C=1.0,
                                                             class_weight='balanced',
                                                             dual=True,
                                                             fit_intercept=True,
                                                             intercept_scaling=1,
                                                             loss='squared_hinge',
                                                             max_iter=10000,
                                                             multi_class='crammer_singer',
                                                             penalty='l2',
                                                             random_state=None,
                                                             tol=0.01,
                                                             verbose=0),
                                    learning_rate=1.5, n_estimators=600,
                                    random_state=None))],
         verbose=False). Check the list of available parameters with `estimator.get_params().keys()`.

没有 AdaBoostClassifier,管道工作正常,所以我认为存在问题。

我认为你的p_grid应该定义如下,

p_grid = {'AdaBoostClassifier__base_estimator__C': np.logspace(-5, 3, 10)}

如果您不确定参数名称,请尝试 pipe_SVC.get_params()