Pipelines Flashcards
What are two ways to display the steps in a pipeline?
# Text version: print(my_pipeline)
# Visual/diagram version: from sklearn import set_config set_config(display='diagram') # display='text' is how you undo this print(my_pipeline)
What are the two methods of a pipeline and what do they do?
.fit(): calls the .fit_transform() method of each transformer component and then calls the .fit() method of the terminal predictor (if one is present)
.predict(): calls the .transform() method of each transformer component and then calls the .predict() method of the terminal predictor (if one is present)
Provide example syntax of defining and running a simple pipeline with one transformer (StandardScaler) and one predictor (LinerRegression).
pipe = Pipeline([(“feature scaling”, StandardScaler()),
(“linear regression”, LinearRegression())])
pipe. fit(X_train, y)
pipe. predict(X-test)
How to spell out the steps of a pipeline?
How to access the attributes of a particular step?
pipe.named_steps
# Works like a dict: pipe.named_steps['linear regression'].coef_
How to spell out the parameters of every step of a pipeline?
my_pipe.get_params()
How do you combine a pipeline with a grid search?
- Feed entire pipeline into the grid search - this one is intuitive
OR
- Have the grid search as one step in the pipeline - not so intuitive