Supervised learning से श्रेणीबद्ध डेटा को एन्कोड करना

R में Feature Engineering

Jorge Zazueta

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

Supervised encoding का परिचय

इसके विपरीत, supervised encoding नाममात्र predictors से outcome मानों का उपयोग करके संख्यात्मक फीचर बनाता है।

R में Feature Engineering

Supervised encoding का परिचय

Supervised encoding नाममात्र predictors से outcome मानों का उपयोग करके संख्यात्मक फीचर बनाता है.

embed पैकेज में उपलब्ध कुछ supervised encoding फंक्शन

Function Definition
step_lencode_glm() Likelihood encodings का उपयोग करके किसी नाममात्र predictor को generalized linear model से निकले एकल स्कोर सेट में बदलता है.
step_lencode_bayes() Bayesian likelihood encodings लागू करके किसी नाममात्र predictor को Bayesian analysis से अनुमानित generalized linear model से निकले एकल स्कोर सेट में बदलता है.
step_lencode_mixed() नाममात्र predictors को generalized linear mixed model से निकले एकल स्कोर सेट में बदलता है.
R में Feature Engineering

Grant application सफलता की भविष्यवाणी

हम केवल sponsor code के आधार पर grant application की सफलता की भविष्यवाणी करना चाहते हैं.

lr_model <- logistic_reg() # declare model

lr_recipe_glm <- # Set recipe glm
  recipe(class ~ sponsor_code, 
         data = grants_train) %>%
  step_lencode_glm(sponsor_code, 
                   # Declare outcome variable
                   outcome = vars(class))

lr_workflow_glm <- # Create Workflow
  workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_glm)

Workflow सारांश

lr_workflow_glm
-- Workflow ------------------------------------
Preprocessor: Recipe
Model: logistic_reg()

-- Preprocessor --------------------------------
1 Recipe Step

- step_lencode_glm()

-- Model --------------------------------------
Logistic Regression Model Specification (classification)

Computational engine: glm
R में Feature Engineering

Fitting, augmenting, और assessing

हम मॉडल fit करते हैं और उसका मूल्यांकन करते हैं

lr_fit_glm <- # Fit
  lr_workflow_glm %>%
  fit(grants_train)

lr_aug_glm <- # Augment
  lr_fit_glm %>%
  augment(grants_test)

glm_model <- lr_aug_glm %>% # Assess
  class_evaluate(truth = class,
                 estimate = .pred_class,
                 .pred_successful)

प्रदर्शन परिणाम glm_model में संग्रहीत हैं

DNT_CURLY_TAG_3

glm_model


# A tibble: 2 × 3 .metric .estimator .estimate <chr> <chr> <dbl> 1 accuracy binary 0.728 2 roc_auc binary 0.684
R में Feature Engineering

मॉडल्स को साथ बाँधना

हम bayes_model और mixed_model बनाकर संबंधित steps के प्रदर्शन की तुलना करते हैं।

# Define model names
model <- c("glm", "glm",
           "bayes","bayes",
           "mixed", "mixed")
# Bind models in a tibble
models <- 
bind_rows(glm_model,
          bayes_model,
          mixed_model)%>%
  add_column(model = model)%>%
  select(-.estimator) %>%
  spread(model,.estimate)

एक सुविधाजनक प्रदर्शन तालिका

models
# A tibble: 2 × 4
  .metric  bayes   glm mixed
  <chr>    <dbl> <dbl> <dbl>
1 accuracy 0.718 0.728 0.720
2 roc_auc  0.686 0.684 0.682
R में Feature Engineering

परिणामों का विज़ुअलाइज़ेशन

Gally पैकेज से parallel coordinates चार्ट में परिणाम visualiz करें।

# Libraries
library(GGally)

# Parallel coordinates chart
ggparcoord(models,
           columns = 2:4, 
           groupColumn = 1,
           scale="globalminmax",
           showPoints = TRUE)

सभी मॉडलों की accuracy और roc_auc का parallel coordinates चार्ट।

सभी मॉडलों की accuracy और roc_auc का parallel coordinates चार्ट.

R में Feature Engineering

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

R में Feature Engineering

Preparing Video For Download...