मॉडल की फीचर्स घटाना

R में Feature Engineering

Jorge Zazueta

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

फीचर्स की संख्या घटाने के कारण

गैर-ज़रूरी या कम-जानकारी वाली वैरिएबल हटाने से फायदे होते हैं, जैसे

  • बायस बढ़ाए बिना मॉडल वेरिएंस घटाएँ
  • आउट-ऑफ-सैंपल परफॉर्मेंस बढ़ाएँ
  • कंप्यूटेशन समय घटाएँ
  • मॉडल जटिलता कम करें
  • व्याख्यात्मकता सुधारें
R में Feature Engineering

वैरिएबल इम्पोर्टेंस से डेटा छाँटना

सभी फीचर्स के साथ मॉडल फिट करना

lr_recipe_full <-
  recipe(Loan_Status ~., data = train) %>%
  update_role(Loan_ID, new_role = "ID")

lr_workflow_full <- 
  workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_full)

lr_fit_full <- 
  lr_workflow_full %>%
  fit(data = train)

वैरिएबल vip का ग्राफ बनाना

lr_fit_full %>%
  extract_fit_parsnip() %>%
  vip(aesthetics = list(fill = "steelblue"))

वैरिएबल इम्पोर्टेंस वैरिएबल इम्पोर्टेंस का कॉलम चार्ट.

R में Feature Engineering

फॉर्मूला सिन्टैक्स से रिड्यूस्ड मॉडल बनाएँ

हम बेसिक R फॉर्मूला सिन्टैक्स से सीधे फीचर्स जोड़ सकते हैं।

# Create recipe
recipe_formula <- 
  recipe(Loan_Status ~ Credit_History + Property_Area + 
           LoanAmount, data = train)

# Bundle with model
workflow_formula <- # Bundle with model
  workflow() %>% add_model(lr_model) %>%
  add_recipe(recipe_formula)
R में Feature Engineering

फीचर वेक्टर बनाकर रिड्यूस्ड मॉडल बनाएँ

ट्रेनिंग से पहले फीचर्स चुनने के लिए एक फीचर वेक्टर पास किया जा सकता है।

# Feature vector
features <- c("Credit_History", "Property_Area", "LoanAmount", "Loan_Status") 

# Training and testing data
train_features <- train %>% select(all_of(features))
test_features <- test %>% select(all_of(features))

# Create recipe and bundle with model
recipe_features <- recipe(Loan_Status ~., data = train_features)
workflow_features <- workflow() %>% add_model(lr_model) %>%
  add_recipe(recipe_features) 
R में Feature Engineering

ऑग्मेंटेड ऑब्जेक्ट्स बनाना

दोनों तरीकों के लिए ऑग्मेंटेड ऑब्जेक्ट्स

lr_aug_formula <-
  workflow_formula %>%
  fit(data = train) %>%
  augment(new_data = test)
lr_aug_features <-
  workflow_features %>%
  fit(data = train_features) %>%
  augment(new_data = test_features)

दोनों तरीके समान परिणाम देते हैं

all_equal(lr_aug_features, 
lr_aug_formula %>%
select(all_of(features),
starts_with(".pred")))
[1] TRUE
R में Feature Engineering

फुल और रिड्यूस्ड मॉडलों की तुलना

सभी फीचर्स का उपयोग

lr_fit_full <- # Fit workflow
  lr_workflow_full %>%
  fit(data = train)
lr_aug_full <- # Augment
  lr_fit_full %>%
  augment(test)
lr_aug_full %>% # Evaluate
  class_evaluate(truth = Loan_Status, 
                 estimate = .pred_class,
                 .pred_Y)
# A tibble: 2 × 3
  .metric  .estimator .estimate
  <chr>    <chr>          <dbl>
1 accuracy binary         0.842
2 roc_auc  binary         0.744

टॉप 3 फीचर्स का उपयोग

lr_fit_formula <- # Fit workflow
  workflow_formula %>%
  fit(train)
lr_aug_formula <- # Augment
  lr_fit_formula %>%
  augment(new_data = test)
lr_aug_formula %>% # Evaluate
  class_evaluate(truth = Loan_Status, 
                 estimate = .pred_class,
                 .pred_Y)
# A tibble: 2 × 3
  .metric  .estimator .estimate
  <chr>    <chr>          <dbl>
1 accuracy binary         0.842
2 roc_auc  binary         0.733
R में Feature Engineering

अभ्यास करते हैं!

R में Feature Engineering

Preparing Video For Download...