Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using StandardScaler() as the model step instead of LogisticRegression()
Forgetting to include a model in the pipeline
✗ Incorrect
The pipeline needs a model step, so LogisticRegression() is the correct choice.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of predict
Calling fit on test data
✗ Incorrect
To get predictions from the pipeline, use the predict method.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pipelines' instead of 'pipeline' in the import
Trying to import Pipeline from a non-existent module
✗ Incorrect
The correct import is from sklearn.pipeline import Pipeline.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing scaler and model imports
Using RandomForestClassifier instead of DecisionTreeClassifier
✗ Incorrect
StandardScaler is used for scaling, and DecisionTreeClassifier is the model.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict to get predictions
Forgetting parentheses when creating scaler or model instances
✗ Incorrect
StandardScaler() scales data, SVC() is the model, and predict gets predictions.