İleri dönüşümler

R'da Feature Engineering

Jorge Zazueta

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

Veriler

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'da Feature Engineering

Düz iş akışıyla tahmin

Tarifi yapılandırın ve iş akışını ayarlayın

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

İş akışını eğitin ve değerlendirin

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)

Düz tarif sonuçları.

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

step_poly() işlevi

step_poly() bir veya daha fazla değişkene polinom genişlemesi uygular ve modeli besler.

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() ile sonuçlar

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'da Feature Engineering

step_percentile() işlevi

step_percentile() eğitim setine göre bir değişkenin ampirik dağılımını belirler ve tüm değerleri yüzdeliklere dönüştürür.

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() ile sonuçlar

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'da Feature Engineering

Hadi pratik yapalım!

R'da Feature Engineering

Preparing Video For Download...