More on Pipelines — Applied Machine Learning in Python

PHOTO EMBED

Tue Oct 24 2023 20:18:30 GMT+0000 (Coordinated Universal Time)

Saved by @elham469

# 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))
content_copyCOPY

https://amueller.github.io/aml/01-ml-workflow/12-pipelines-gridsearch.html