Logistic regression

A/B Testing ใน R

Lauryn Burleigh

Data Scientist

Log ใน logistic

  • ตัวแปรตาม Binary
    • กินพิซซ่าอีกครั้ง - ใช่/ไม่ใช่
  • หาความน่าจะเป็นของแต่ละหมวดหมู่
  • ตัวแปรตามที่พยากรณ์
    • Odds = P / 1-P
    • มีความสัมพันธ์เชิงเส้นกับตัวแปรอิสระ
  • log(P / 1-P) = β₀ + β₁X₁
    • ความคลาดเคลื่อนอยู่ใน log odds

กราฟกระจายที่แกน x คือ enjoy และแกน y คือ eat again โดยจุดข้อมูลอยู่ที่ 0 หรือ 1 พร้อมเส้นโค้ง logistic regression

A/B Testing ใน R

โมเดล Logistic regression

logistic <- glm(EatAgain ~ Enjoy, 
                data = Pizza, 
                family = binomial)
summary(logistic)
chival <- logistic$null.deviance - logistic$deviance
dfval <- logistic$df.null - logistic$df.residual
pchisq(q = chival, df = dfval, lower.tail = FALSE)
[1] 7.472441e-16
Call:
glm(formula = EatAgain ~ Enjoy, family = binomial, 
data = pizza)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.9677   0.0116   0.0297   0.0885   0.9446  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)  -4.2361     1.4757  -2.871 0.004097 ** 
Enjoy         0.9611     0.2533   3.794 0.000148 ***

Null deviance: 96.204  on 199  degrees of freedom
Residual deviance: 31.199  on 198  degrees of freedom
AIC: 35.199
Number of Fisher Scoring iterations: 9
A/B Testing ใน R

การพยากรณ์ข้อมูล

Enjoy  <- c(12, 14)
topredict <-  data.frame(Enjoy) 
predict(logistic, topredict, 
        type = "response") 
        1         2 
0.9993229 0.9999009 
A/B Testing ใน R

การรวมกลุ่ม

grplogistic <- glm(EatAgain ~ Enjoy + 
                   Topping, 
                   data = pizza, 
                   family = binomial)
summary(grplogistic)
Call:
glm(formula = EatAgain ~ Enjoy + Topping, family = binomial, 
    data = pizza)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.8557   0.0058   0.0222   0.0862   0.8887  

Coefficients:
                 Estimate Std. Error z value Pr(>|z|)   
(Intercept)       -9.4498     3.8806  -2.435  0.01489 * 
Enjoy              1.3402     0.4118   3.255  0.00114 **
ToppingCheese   3.4652     2.0499   1.690  0.09095 . 

Null deviance: 96.204  on 199  degrees of freedom
Residual deviance: 28.232  on 197  degrees of freedom
AIC: 34.232

Number of Fisher Scoring iterations: 9
A/B Testing ใน R

มาฝึกกันเถอะ!

A/B Testing ใน R

Preparing Video For Download...