特徵選取 vs. 特徵擷取

R 的降維

Matt Pickard

Owner, Pickard Predictives, LLC

降維方法

菜園

  • 特徵選取 像拔雜草
  • 特徵擷取 像做沙拉
1 圖片來源:Daderot,CC0,取自 Wikimedia Commons
R 的降維

特徵選取

六個以色彩標示的特徵集

R 的降維

特徵選取

篩掉低資訊特徵的六個特徵集

R 的降維

特徵選取

篩選後的四個特徵

R 的降維

信用資料範例

credit_df %>% head(n=5)
  annual_income num_bank_accounts num_credit_card outstanding_debt credit_history_months
          <dbl>             <dbl>           <dbl>            <dbl>                 <dbl>
1        87630.                 2               5             526.                   286
2        16574.                 2               5              NA                    122
3        24931.                 2               5              NA                    351
4       136680.                 2               5              NA                    216
5        76850.                 2               5            1112.                   272
R 的降維

建立零變異篩選器

na_filter <- credit_df %>% 
  summarize(across(everything(), ~ var(., na.rm = TRUE))) %>%

pivot_longer(everything(), names_to = "feature", values_to = "variance") %>%
filter(variance == 0) %>%
pull(feature)
na_filter
"num_bank_accounts" "num_credit_card"
R 的降維

建立遺漏值篩選器

na_filter <- credit_df %>%  
  summarize(across(everything(), ~ sum(is.na(.)))) %>%

pivot_longer(everything(), names_to = "feature", values_to = "num_missing_values") %>%
filter(num_missing_values > 0) %>%
pull(feature)
na_filter
"outstanding_debt"
R 的降維

套用合併篩選器

combined_filter <- 
  c(low_var_filter, na_filter)

credit_df %>% 
  select(-all_of(combined_filter)) %>% 
  head(3)
  annual_income credit_history_months
          <dbl>                 <dbl>
1        87630.                   286
2        16574.                   122
3        24931.                   351
R 的降維

特徵擷取

六個以色彩標示的特徵集

R 的降維

特徵擷取

合併部分特徵成四個特徵

R 的降維

特徵擷取與互資訊

有交集的維恩圖

R 的降維

特徵擷取:合併互斥資訊

合併含互資訊與互斥資訊的特徵

R 的降維

特徵擷取:合併互斥資訊

移除互資訊後的合併特徵

R 的降維

特徵擷取的優缺點

優點
  • 可將資訊結合成新特徵
缺點
  • 實作較複雜
  • 新特徵不易解讀

身體質量指數、身高與體重的主成分分析

R 的降維

一起來練習吧!

R 的降維

Preparing Video For Download...