0
0
ML Pythonml~10 mins

Feature union 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 class used to combine features.

ML Python
from sklearn.pipeline import [1]
Drag options to blanks, or click blank then click option'
AStandardScaler
BPCA
CFeatureUnion
DGridSearchCV
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated classes like StandardScaler or PCA.
Confusing FeatureUnion with Pipeline.
2fill in blank
medium

Complete 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'
AStandardScaler
BMinMaxScaler
COneHotEncoder
DPolynomialFeatures
Attempts:
3 left
💡 Hint
Common Mistakes
Using OneHotEncoder which is for categorical data encoding.
Using PolynomialFeatures which creates new features.
3fill in blank
hard

Fix 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'
Apredict
Bfit_transform
Ctransform
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform() before fitting causes errors.
Using predict() which is for models, not transformers.
4fill in blank
hard

Fill 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'
AFeatureUnion(transformer_list=[('pca', PCA(n_components=2)), ('scaler', StandardScaler())])
BLogisticRegression()
CRandomForestClassifier()
DStandardScaler()
Attempts:
3 left
💡 Hint
Common Mistakes
Using StandardScaler as the classifier step.
Using RandomForestClassifier when LogisticRegression is expected.
5fill in blank
hard

Fill 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'
APCA(n_components=3)
BStandardScaler()
Cfit_transform
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of fit_transform for transformation.
Mixing up transformer instances with method names.