sklearn 管道的参数无效

Invalid parameter for sklearn pipeline

我知道这似乎是一个常见问题,并且它基于参数的特定名称,但在查看键后我仍然遇到错误。

steps=[('classifier', svm.SVC(decision_function_shape="ovo"))]

pipeline = Pipeline(steps)

# Specify the hyperparameter space
parameters = {'estimator__classifier__C':[1, 10, 100],
              'estimator__classifier__gamma':[0.001, 0.0001]}

# Instantiate the GridSearchCV object: cv
SVM = GridSearchCV(pipeline, parameters, cv = 5)

_ = SVM.fit(X_train,y_train)

然后我得到: ValueError: Invalid parameter estimator for estimator ... Check the list of available parameters with `estimator.get_params().keys()`.

然后我查看 SVM.get_params().keys() 并获得以下组,包括我正在使用的两个。我错过了什么?

简历 error_score estimator__memory estimator__steps estimator__verbose estimator__preprocessor estimator__classifier estimator__preprocessor__n_jobs estimator__preprocessor__剩余 estimator__preprocessor__sparse_threshold estimator__preprocessor__transformer_weights estimator__preprocessor__变形金刚 estimator__preprocessor__详细 estimator__preprocessor__规模 estimator__preprocessor__onehot estimator__preprocessor__scale__内存 estimator__preprocessor__scale__steps estimator__preprocessor__scale__verbose estimator__preprocessor__scale__scaler estimator__preprocessor__scale__scaler__copy estimator__preprocessor__scale__scaler__with_mean estimator__preprocessor__scale__scaler__with_std estimator__preprocessor__onehot__内存 estimator__preprocessor__onehot__steps estimator__preprocessor__onehot__详细 estimator__preprocessor__onehot__onehot estimator__preprocessor__onehot__onehot__类别 estimator__preprocessor__onehot__onehot__drop estimator__preprocessor__onehot__onehot__dtype estimator__preprocessor__onehot__onehot__handle_unknown estimator__preprocessor__onehot__onehot__sparse estimator__classifier__C estimator__classifier__break_ties estimator__classifier__cache_size estimator__classifier__class_weight estimator__classifier__coef0 estimator__classifier__decision_function_shape estimator__classifier__学位 estimator__classifier__伽玛 estimator__classifier__内核 estimator__classifier__max_iter estimator__classifier__概率 estimator__classifier__random_state estimator__classifier__收缩 estimator__classifier__托尔 estimator__classifier__详细 估算器 iid n_jobs param_grid pre_dispatch 改装 return_train_score 计分 详细

您的参数网格应为 classifier__Cclassifier__gamma。您只需要去掉前面的 estimator,因为您在管道中将 SVC 估算器命名为 classifier

parameters = {'classifier__C':[1, 10, 100],
              'classifier__gamma':[0.001, 0.0001]}