0
0
ML Pythonml~10 mins

Why pipelines ensure reproducibility in ML Python - Test Your Understanding

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

Complete the code to create a pipeline that standardizes data and fits a model.

ML Python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression

pipeline = Pipeline(steps=[('scaler', StandardScaler()), ('model', [1])])
pipeline.fit(X_train, y_train)
Drag options to blanks, or click blank then click option'
AKMeans()
BStandardScaler()
CRandomForestClassifier()
DLogisticRegression()
Attempts:
3 left
💡 Hint
Common Mistakes
Using StandardScaler() as the model step instead of LogisticRegression()
Forgetting to include a model in the pipeline
2fill in blank
medium

Complete the code to apply the pipeline to transform test data and predict labels.

ML Python
y_pred = pipeline.[1](X_test)
Drag options to blanks, or click blank then click option'
Afit
Bpredict
Cfit_transform
Dtransform
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of predict
Calling fit on test data
3fill in blank
hard

Fix the error in the pipeline creation by selecting the correct import for the pipeline class.

ML Python
from sklearn.[1] import Pipeline

pipeline = Pipeline(steps=[('scaler', StandardScaler()), ('model', LogisticRegression())])
Drag options to blanks, or click blank then click option'
Apipeline
Bpipelines
Cpipeline_module
Dpipeline_class
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pipelines' instead of 'pipeline' in the import
Trying to import Pipeline from a non-existent module
4fill in blank
hard

Fill both blanks to create a pipeline that scales data and fits a decision tree model.

ML Python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import [1]
from sklearn.tree import [2]

pipeline = Pipeline(steps=[('scaler', StandardScaler()), ('model', DecisionTreeClassifier())])
Drag options to blanks, or click blank then click option'
AStandardScaler
BMinMaxScaler
CDecisionTreeClassifier
DRandomForestClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing scaler and model imports
Using RandomForestClassifier instead of DecisionTreeClassifier
5fill in blank
hard

Fill all three blanks to create a pipeline, fit it, and get the accuracy score.

ML Python
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

pipeline = Pipeline(steps=[('scaler', [1]), ('model', [2])])
pipeline.fit(X_train, y_train)
y_pred = pipeline.[3](X_test)
score = accuracy_score(y_test, y_pred)
Drag options to blanks, or click blank then click option'
AStandardScaler()
BSVC()
Cpredict
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict to get predictions
Forgetting parentheses when creating scaler or model instances