【问题标题】:Adaboost in Pipeline with Gridsearch SKLEARN使用 Gridsearch SKLEARN 在管道中进行 Adaboost
【发布时间】:2020-02-20 17:18:27
【问题描述】:

我想使用带有 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,管道正在工作,所以我认为有问题。

【问题讨论】:

    标签: scikit-learn pipeline adaboost gridsearchcv


    【解决方案1】:

    我觉得你的p_grid应该定义如下,

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

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

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 2016-09-19
      • 2017-07-01
      • 2020-02-10
      • 2018-12-01
      • 2014-11-07
      • 2018-09-24
      • 2015-03-26
      • 1970-01-01
      相关资源
      最近更新 更多