sklearn管道的参数无效

时间:2020-05-24 00:40:37

标签: python scikit-learn pipeline grid-search gridsearchcv

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

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__verbose estimator__preprocessor estimator__classifier estimator__preprocessor__n_jobs estimator__preprocessor__remainder estimator__preprocessor__sparse_threshold estimator__preprocessor__transformer_weights estimator__preprocessor__transformers estimator__preprocessor__verbose estimator__preprocessor__scale estimator__preprocessor__onehot estimator__preprocessor__scale__内存 估计器__预处理器__缩放__步骤 estimator__preprocessor__scale__verbose estimator__preprocessor__scale__scaler estimator__preprocessor__scale__scaler__copy 估计器__预处理器__缩放__缩放器__with_mean estimator__preprocessor__scale__scaler__with_std estimator__preprocessor__onehot__内存 estimator__preprocessor__onehot__steps estimator__preprocessor__onehot__verbose 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__稀疏 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__gamma estimator__classifier__kernel estimator__classifier__max_iter 估计器__分类器__概率 estimator__classifier__random_state estimator__classifier__收缩 estimator__classifier__tol estimator__classifier__verbose 估计量 艾德 n_jobs param_grid pre_dispatch 改装 return_train_score 得分 详细

1 个答案:

答案 0 :(得分:1)

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

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