0
0
ML Pythonml~10 mins

scikit-learn Pipeline in ML Python - 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.

ML Python
from sklearn.pipeline import [1]
Drag options to blanks, or click blank then click option'
APipeline
Bpipe
CPipeLine
Dpipeline
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'pipeline' instead of 'Pipeline'.
Misspelling the class name with wrong capitalization.
2fill in blank
medium

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

ML Python
pipeline = Pipeline(steps=[('scaler', [1]()), ('model', LogisticRegression())])
Drag options to blanks, or click blank then click option'
AstandardScaler
BScalerStandard
CStandardScaler
Dscale
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like 'ScalerStandard' or lowercase variants.
Forgetting to import StandardScaler before using it.
3fill in blank
hard

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

ML Python
pipeline.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Afit
Bfit_transform
Ctransform
Dtrain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' which is not a method in scikit-learn.
Using 'transform' which does not accept labels.
4fill in blank
hard

Fill both blanks to create a pipeline that first applies PCA and then a classifier.

ML Python
pipeline = Pipeline(steps=[('pca', [1](n_components=2)), ('clf', [2]())])
Drag options to blanks, or click blank then click option'
APCA
BLogisticRegression
CRandomForestClassifier
DStandardScaler
Attempts:
3 left
💡 Hint
Common Mistakes
Using StandardScaler instead of PCA for the first step.
Using LogisticRegression when the question expects RandomForestClassifier.
5fill in blank
hard

Fill all three blanks to create a pipeline that scales data, reduces dimensions, and classifies.

ML Python
pipeline = Pipeline(steps=[('scale', [1]()), ('reduce', [2](n_components=3)), ('classify', [3]())])
Drag options to blanks, or click blank then click option'
AStandardScaler
BPCA
CLogisticRegression
DKNeighborsClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of steps in the pipeline.
Using KNeighborsClassifier instead of LogisticRegression as classifier.