Preview:
# create a pipeline
select_pipe = make_pipeline(StandardScaler(), SelectPercentile(), KNeighborsClassifier())
# create the search grid.
# Pipeline hyper-parameters are specified as <step name>__<hyper-parameter name>
param_grid = {'kneighborsclassifier__n_neighbors': range(1, 10),
              'selectpercentile__percentile': [1, 2, 5, 10, 50, 100]}
# Instantiate grid-search
grid = GridSearchCV(select_pipe, param_grid, cv=10)
# run the grid-search and report results
grid.fit(X_train, y_train)
print(grid.best_params_)
print(grid.score(X_test, y_test))
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter