Removing highly correlated features

Riduzione della dimensionalità in Python

Jeroen Boeye

Head of Machine Learning, Faktion

Highly correlated data

highly correlated pairplot

Riduzione della dimensionalità in Python

Highly correlated features

highly correlated matrix

Riduzione della dimensionalità in Python

Removing highly correlated features

# Create positive correlation matrix
corr_df = chest_df.corr().abs()

# Create and apply mask mask = np.triu(np.ones_like(corr_df, dtype=bool))
tri_df = corr_df.mask(mask) tri_df

Riduzione della dimensionalità in Python

Removing highly correlated features

# Find columns that meet threshold 
to_drop = [c for c in tri_df.columns if any(tri_df[c] > 0.95)]

print(to_drop)
['Suprasternale height', 'Cervicale height']
# Drop those columns
reduced_df = chest_df.drop(to_drop, axis=1)
Riduzione della dimensionalità in Python

Feature selection

Feature selection schema

Feature extraction

Feature extraction schema

Riduzione della dimensionalità in Python

Correlation caveats - Anscombe's quartet

Anscombe's quartet

Riduzione della dimensionalità in Python

Correlation caveats - causation

sns.scatterplot(x="N firetrucks sent to fire", 
                y="N wounded by fire",data=fire_df)

firetrucks vs. wounded

Riduzione della dimensionalità in Python

Let's practice!

Riduzione della dimensionalità in Python

Preparing Video For Download...