Features with low variance
In the previous exercise you established that 0.001 is a good threshold to filter out low variance features in head_df after normalization. Now use the VarianceThreshold feature selector to remove these features.
Diese Übung ist Teil des Kurses
Dimensionality Reduction in Python
Anleitung zur Übung
- Create the variance threshold selector with a threshold of 0.001.
- Normalize the
head_dfDataFrame by dividing it by its mean values and fit the selector. - Create a boolean mask from the selector using
.get_support(). - Create a reduced DataFrame by passing the mask to the
.loc[]method.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
from sklearn.feature_selection import VarianceThreshold
# Create a VarianceThreshold feature selector
sel = ____(threshold=____)
# Fit the selector to normalized head_df
sel.fit(____ / ____)
# Create a boolean mask
mask = sel.____
# Apply the mask to create a reduced DataFrame
reduced_df = head_df.loc[____, ____]
print(f"Dimensionality reduced from {head_df.shape[1]} to {reduced_df.shape[1]}.")