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.
Este exercício faz parte do curso
Dimensionality Reduction in Python
Instruções do exercício
- Create the variance threshold selector with a threshold of 0.001.
- Normalize the
head_df
DataFrame 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
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]}.")