Invalid parameter for sklearn estimator pipeline

前端 未结 2 574
不知归路
不知归路 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.

提交回复
热议问题