고급 변환

R로 배우는 Feature Engineering

Jorge Zazueta

Research Professor and Head of the Modeling Group at the School of Economics, UASLP

데이터

Rows: 480
Columns: 6
$ Loan_Status       <fct> N, Y, Y, Y, Y, Y, N, Y, N, Y, Y, N, Y, Y, N, N, ...
$ ApplicantIncome   <dbl> 4583, 3000, 2583, 6000, 5417, 2333, 3036, 4006, ...
$ CoapplicantIncome <dbl> 1508, 0, 2358, 0, 4196, 1516, 2504, 1526, 10968,...
$ LoanAmount        <dbl> 128, 66, 120, 141, 267, 95, 158, 168, 349, 70, 2...
$ Loan_Amount_Term  <dbl> 360, 360, 360, 360, 360, 360, 360, 360, 360, 360...
$ Credit_History    <fct> 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, ...
R로 배우는 Feature Engineering

기본 워크플로로 예측

레시피를 설정하고 워크플로를 구성합니다

lr_recipe_plain <- 
  recipe(Loan_Status ~., data = train)
lr_workflow_poly <-
  workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_plain)

워크플로를 학습하고 평가합니다

lr_fit_plain <-
  lr_workflow_plain %>% fit(train)
lr_aug_plain <-
  lr_fit_plain %>% augment(test)
lr_aug_plain %>%
  class_evaluate(truth = Loan_Status,
                 estimate = .pred_class,
                 .pred_N)

기본 레시피 결과

# A tibble: 2 × 3
  .metric  .estimator .estimate
  <chr>    <chr>          <dbl>
1 accuracy binary         0.75 
2 roc_auc  binary         0.595
R로 배우는 Feature Engineering

step_poly() 함수

step_poly()는 하나 이상의 변수에 다항 확장을 적용하여 모델에 전달합니다.

lr_recipe_poly <- 
  recipe(Loan_Status ~., data = train) %>%
  step_poly(all_numeric_predictors())
lr_workflow_poly <-
  workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_poly)

step_poly() 결과

DNT_CURLY_TAG_4

# A tibble: 2 × 3
  .metric  .estimator .estimate
  <chr>    <chr>          <dbl>
1 accuracy binary         0.75 
2 roc_auc  binary         0.703
R로 배우는 Feature Engineering

step_percentile() 함수

step_percentile()은 학습 세트 기반으로 변수의 경험적 분포를 계산하고, 모든 값을 분위수로 변환합니다.

lr_recipe_perc <- 
  recipe(Loan_Status ~., data = train) %>%
  step_percentile(all_numeric_predictors())
lr_workflow_perc <-
  workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_perc)

step_percentile() 결과

DNT_CURLY_TAG_3

# A tibble: 2 × 3
  .metric  .estimator .estimate
  <chr>    <chr>          <dbl>
1 accuracy binary         0.769

2 roc_auc  binary         0.677
R로 배우는 Feature Engineering

연습해 봅시다!

R로 배우는 Feature Engineering

Preparing Video For Download...