ComenzarEmpieza gratis

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 ejercicio forma parte del curso

Dimensionality Reduction in Python

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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]}.")
Editar y ejecutar código