Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the class used to combine features.
ML Python
from sklearn.pipeline import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like StandardScaler or PCA.
Confusing FeatureUnion with Pipeline.
✗ Incorrect
FeatureUnion is the class used to combine multiple feature extraction processes into one.
2fill in blank
mediumComplete the code to create a FeatureUnion combining two transformers.
ML Python
union = FeatureUnion(transformer_list=[('pca', PCA(n_components=2)), ('scaler', [1]())])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using OneHotEncoder which is for categorical data encoding.
Using PolynomialFeatures which creates new features.
✗ Incorrect
StandardScaler is commonly used to scale features before combining them.
3fill in blank
hardFix the error in the code to correctly fit the FeatureUnion on data X.
ML Python
union = FeatureUnion(transformer_list=[('pca', PCA(n_components=2)), ('scaler', StandardScaler())]) union.[1](X)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform() before fitting causes errors.
Using predict() which is for models, not transformers.
✗ Incorrect
To prepare the FeatureUnion for transformation, we first call fit on the data.
4fill in blank
hardFill both blanks to create a pipeline that first applies FeatureUnion then fits a classifier.
ML Python
pipeline = Pipeline([('features', [1]), ('clf', [2])])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using StandardScaler as the classifier step.
Using RandomForestClassifier when LogisticRegression is expected.
✗ Incorrect
FeatureUnion combines features, then LogisticRegression fits the combined features.
5fill in blank
hardFill all three blanks to create a FeatureUnion with two transformers and fit_transform on data X.
ML Python
union = FeatureUnion(transformer_list=[('pca', [1]), ('scaler', [2])]) X_transformed = union.[3](X)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of fit_transform for transformation.
Mixing up transformer instances with method names.
✗ Incorrect
PCA and StandardScaler are transformers; fit_transform fits and transforms the data.