Invalid parameter for sklearn estimator pipeline

前端 未结 2 557
不知归路
不知归路 2021-02-03 22:03

I am implementing an example from the O\'Reilly book \"Introduction to Machine Learning with Python\", using Python 2.7 and sklearn 0.16.

The code I am using:

相关标签:
2条回答
  • 2021-02-03 22:26

    Note that if you are using a pipeline with a voting classifier and a column selector, you will need multiple layers of names:

    pipe1 = make_pipeline(ColumnSelector(cols=(0, 1)),
                          LogisticRegression())
    pipe2 = make_pipeline(ColumnSelector(cols=(1, 2, 3)),
                          SVC())
    votingClassifier = VotingClassifier(estimators=[
            ('p1', pipe1), ('p2', pipe2)])
    

    You will need a param grid that looks like the following:

    param_grid = { 
            'p2__svc__kernel': ['rbf', 'poly'],
            'p2__svc__gamma': ['scale', 'auto'],
        }
    

    p2 is the name of the pipe and svc is the default name of the classifier you create in that pipe. The third element is the parameter you want to modify.

    0 讨论(0)
  • 2021-02-03 22:27

    There should be two underscores between estimator name and it's parameters in a Pipeline logisticregression__C. Do the same for tfidfvectorizer

    See the example at http://scikit-learn.org/stable/auto_examples/plot_compare_reduction.html#sphx-glr-auto-examples-plot-compare-reduction-py

    0 讨论(0)
提交回复
热议问题