결측값 기준 선택

R에서의 차원 축소

Matt Pickard

Owner, Pickard Predictives, LLC

결측값 비율 계산

결측값 비율 식

n <- nrow(credit_df)


missing_vals_df <- credit_df %>% summarize(across(everything(), ~ sum(is.na(.)))) %>%
pivot_longer(everything(), names_to = "feature", values_to = "num_missing_values") %>%
mutate(missing_val_ratio = num_missing_values / n)
R에서의 차원 축소

결측값 비율 결과

missing_vals_df
# A tibble: 5 × 3
  feature          num_missing_values missing_val_ratio
  <chr>                         <int>             <dbl>
1 credit_score                      0             0    
2 annual_income                     0             0    
3 age                              84             0.613
4 outstanding_debt                129             0.942
5 num_of_loan                       0             0  
R에서의 차원 축소

결측값 비율 임계값 경험칙

  • 절대 기준은 없음
  • 특성 중요도에 따라 다름
    • 예: outstanding_debt vs. age

결측값 비율 임계값 경험칙 표

R에서의 차원 축소

결측값 필터 생성

missing_vals_filter <- missing_vals_df %>% 
  filter(missing_val_ratio <= 0.5) %>%

pull(feature)
missing_vals_filter
[1] "credit_score"  "annual_income" "num_of_loan"
R에서의 차원 축소

결측값 필터 적용

filtered_credit_df <- credit_df %>% 
  select(missing_vals_filter)

filtered_credit_df %>% head(3)
# A tibble: 5 × 3
  credit_score annual_income num_of_loan
  <chr>                <dbl>       <dbl>
1 Standard            87630.           4
2 Standard            16574.           7
3 Standard            24931.           2
R에서의 차원 축소

tidymodels 접근법

레시피 생성

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

step_filter_missing(all_predictors(), threshold = 0.5) %>%
prep()

레시피 적용

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

베이크된 레시피 결과

filtered_credit_df %>% head(5)
# A tibble: 5 × 3
  annual_income num_of_loan credit_score
          <dbl>       <dbl> <fct>       
1        87630.           4 Standard    
2        16574.           7 Standard    
3        24931.           2 Standard    
4       136680.           1 Good        
5        76850.           3 Standard 
R에서의 차원 축소

연습해 봅시다!

R에서의 차원 축소

Preparing Video For Download...