0
0
SciPydata~10 mins

SciPy with scikit-learn pipeline - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Pipeline class from scikit-learn.

SciPy
from sklearn.pipeline import [1]
Drag options to blanks, or click blank then click option'
APipeline
Bpipeline
CPipe
DPipelines
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'pipeline' instead of 'Pipeline'.
Trying to import 'Pipe' or 'Pipelines' which do not exist.
2fill in blank
medium

Complete the code to create a pipeline with a scaler and a logistic regression model.

SciPy
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression

pipeline = Pipeline([('scaler', [1]()), ('clf', LogisticRegression())])
Drag options to blanks, or click blank then click option'
AMinMaxScaler
BStandardScaler
CNormalizer
DRobustScaler
Attempts:
3 left
💡 Hint
Common Mistakes
Using a scaler that does not standardize data like MinMaxScaler.
Forgetting to instantiate the scaler with parentheses.
3fill in blank
hard

Fix the error in the code to fit the pipeline on training data X_train and y_train.

SciPy
pipeline = Pipeline([('scaler', StandardScaler()), ('clf', LogisticRegression())])
pipeline.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Afit
Btransform
Cpredict
Dfit_transform
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'transform' which only changes data but does not train.
Using 'predict' before training the model.
4fill in blank
hard

Fill both blanks to create a pipeline that scales data and then applies a KNeighborsClassifier.

SciPy
from sklearn.neighbors import [1]
pipeline = Pipeline([('scaler', StandardScaler()), ('knn', [2]())])
Drag options to blanks, or click blank then click option'
AKNeighborsClassifier
BLogisticRegression
CRandomForestClassifier
DSVC
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a different classifier than the one used in the pipeline.
Using different classifiers in import and pipeline steps.
5fill in blank
hard

Fill all three blanks to create a pipeline that scales data, applies PCA for dimensionality reduction, and then fits a logistic regression model.

SciPy
from sklearn.decomposition import [1]
from sklearn.linear_model import [2]
pipeline = Pipeline([('scaler', StandardScaler()), ('pca', [3](n_components=2)), ('clf', LogisticRegression())])
Drag options to blanks, or click blank then click option'
APCA
BLogisticRegression
DRandomForestClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing PCA with other decomposition methods.
Using a different classifier than logistic regression.