प्रोबैबिलिटी की भविष्यवाणी के लिए Logistic Regression

R में Supervised Learning: Regression

Nina Zumel and John Mount

Win-Vector LLC

Probabilities की भविष्यवाणी

  • घटना होगी या नहीं (yes/no) की भविष्यवाणी: classification
  • घटना होने की probability की भविष्यवाणी: regression
  • Linear regression: मान [$-\infty$, $\infty$] में देता है
  • Probabilities: [0,1] तक सीमित
    • इसलिए इसे non-linear मानेंगे
R में Supervised Learning: Regression

उदाहरण: Duchenne Muscular Dystrophy (DMD) की भविष्यवाणी

  • outcome: has_dmd inputs: CK, H
R में Supervised Learning: Regression

एक Linear Regression मॉडल

model <- lm(has_dmd ~ CK + H, 
            data = train)

test$pred <- predict(
    model, 
    newdata = test
)

outcome: has_dmd $\in$ {0,1}

  • 0: FALSE
  • 1: TRUE

मॉडल [0:1] रेंज के बाहर मान देता है

R में Supervised Learning: Regression

Logistic Regression

$$ log(\frac{p}{1-p}) = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + ... $$

glm(formula, data, family = binomial)
  • Generalized linear model
  • मानता है इनपुट additive हैं, log-odds में linear: $log( p/(1-p) )$
  • family: मॉडल की error distribution
    • logistic regression: family = binomial
R में Supervised Learning: Regression

DMD मॉडल

model <- glm(has_dmd ~ CK + H, data = train, family = binomial)
  • outcome: दो classes, जैसे $a$ और $b$
  • मॉडल $Prob(b)$ लौटाता है
    • सुझाया गया आउटपुट: 0/1 या FALSE/TRUE
R में Supervised Learning: Regression

Logistic Regression मॉडलों की व्याख्या

model
Call:  glm(formula = has_dmd ~ CK + H, family = binomial, data = train)

Coefficients:
(Intercept)           CK            H  
  -16.22046      0.07128      0.12552  

Degrees of Freedom: 86 Total (i.e. Null);  84 Residual
Null Deviance:       110.8 
Residual Deviance: 45.16     AIC: 51.16
R में Supervised Learning: Regression

glm() मॉडल से prediction

predict(model, newdata, type = "response")
  • newdata: डिफ़ॉल्ट रूप से training data
  • probabilities पाने के लिए: type = "response" दें
    • डिफ़ॉल्ट: log-odds लौटाता है
R में Supervised Learning: Regression

DMD मॉडल

model <- glm(has_dmd ~ CK + H, data = train, family = binomial)
test$pred <- predict(model, newdata = test, type = "response")

R में Supervised Learning: Regression

Logistic regression का मूल्यांकन: pseudo-$R^2$

$$ R^2 = 1 - \frac{RSS}{SS_{Tot}} $$

$$ pseudo R^2 = 1 - \frac{deviance}{null.deviance} $$

  • Deviance: variance (RSS) जैसा
  • Null deviance: $SS_{Tot}$ जैसा
  • pseudo R^2: समझाई गई deviance
R में Supervised Learning: Regression

Training data पर pseudo-$R^2$

broom::glance() का उपयोग

glance(model) %>% 
  summarize(pR2 = 1 - deviance/null.deviance)
   pseudoR2
1 0.5922402

sigr::wrapChiSqTest() का उपयोग

wrapChiSqTest(model)
"... pseudo-R2=0.59 ..."
R में Supervised Learning: Regression

Test data पर pseudo-$R^2$

# Test data
test %>% 
  mutate(pred = predict(model, newdata = test, type = "response")) %>%
  wrapChiSqTest("pred", "has_dmd", TRUE)

आर्ग्युमेंट्स:

  • data frame
  • prediction कॉलम का नाम
  • outcome कॉलम का नाम
  • target value (target event)
R में Supervised Learning: Regression

Gain Curve Plot

GainCurvePlot(test, "pred","has_dmd", "DMD model on test")

R में Supervised Learning: Regression

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

R में Supervised Learning: Regression

Preparing Video For Download...