분산 기준으로 선택하기

R에서의 차원 축소

Matt Pickard

Owner, Pickard Predictives, LLC

비스케일 데이터의 분산

스케일링하지 않은 신용 데이터의 평균 플롯(표준편차 오차막대 포함)

R에서의 차원 축소

스케일된 데이터의 분산

스케일된 신용 데이터의 평균 플롯(표준편차 오차막대 포함)

R에서의 차원 축소

스케일 분산 계산

credit_variances <- credit_df %>% 
  summarize(across(everything(), ~ var(scale(., center = FALSE)), na.rm = TRUE)) %>%

pivot_longer(everything(), names_to = "feature", values_to = "variance") %>%
arrange(desc(variance)) credit_variances
# A tibble: 17 × 2
   feature                  variance
   <chr>                       <dbl>
 1 num_of_loan               0.996  
 2 num_of_delayed_payment    0.986   
 ...
R에서의 차원 축소

분산 임계값

분산 출력

R에서의 차원 축소

분산 임계값

첫 번째 가능 임계값을 보여주는 분산 출력

R에서의 차원 축소

분산 임계값

첫 번째 가능 임계값을 보여주는 분산 출력

R에서의 차원 축소

분산 임계값

첫 번째 가능 임계값을 보여주는 분산 출력

R에서의 차원 축소

분산 임계값 플롯

분산 임계값 플롯

R에서의 차원 축소

분산 필터 생성

low_var_filter <- credit_variances %>% 
  filter(variance < 0.1) %>% 
  pull(feature)

low_var_filter
[1] "credit_history_months"    "age"                     
[3] "num_credit_inquiries"     "credit_utilization_ratio"
[5] "num_credit_card"   
R에서의 차원 축소

tidymodels 접근법

레시피 생성

low_variance_recipe <- recipe(credit_score ~ ., data = credit_df) %>%

step_zv(all_predictors()) %>%
step_scale(all_numeric_predictors()) %>%
step_nzv(all_predictors()) %>%
prep()

레시피 적용

filtered_credit_df <- bake(low_variance_recipe, new_data = NULL)
R에서의 차원 축소

특정 단계의 효과 살펴보기

low_variance_recipe <- recipe(credit_score ~ ., data = credit_df) %>% 
  step_zv(all_predictors()) %>% 
  step_scale(all_numeric_predictors()) %>% 
  step_nzv(all_predictors()) %>% 
  prep() 

tidy(low_variance_recipe, number = 3)
  terms                id       
  <chr>                <chr>    
1 num_credit_card      nzv_ni8L7
2 num_credit_inquiries nzv_ni8L7
R에서의 차원 축소

연습해 봅시다!

R에서의 차원 축소

Preparing Video For Download...