移除高度相關的特徵

Python 的降維

Jeroen Boeye

Head of Machine Learning, Faktion

高度相關的資料

高度相關的 pairplot

Python 的降維

高度相關的特徵

高度相關的相關矩陣

Python 的降維

移除高度相關的特徵

# 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

Python 的降維

移除高度相關的特徵

# 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)
Python 的降維

特徵選擇

特徵選擇示意圖

特徵萃取

特徵萃取示意圖

Python 的降維

相關性的注意事項-Anscombe 四胞胎

Anscombe 四胞胎

Python 的降維

相關性的注意事項-因果關係

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

消防車數量與受傷人數

Python 的降維

一起來練習吧!

Python 的降維

Preparing Video For Download...