0
$\begingroup$

I am using Logistic Regression to create a binary classifier in R. Wrote a predictor for test data, and calculated the mean of my predicted result (I guess it can be translated to the efficiency of my method). I did find some references to training and test errors calculation, but can't seem to understand how to calculate them from the predicted fit. Any reference will help!

    glm.fit=glm(salary~age+workclass+fnlwgt+education+education.num+marital.status
        +occupation+relationship+race+sex+capital.gain+capital.loss
        +hours.per.week+native.country,
        data=trainAdults,family=binomial)
    summary(glm.fit)
    glm.probs=predict(glm.fit,newdata=testAdults, type="response") 
    glm.probs[1:10]
    glm.pred=ifelse(glm.probs>0.5,"2","1")
    setattr(testAdults$salary,"levels",c(1, 2))
    attach(testAdults)
    table(glm.pred,salary)
    mean(glm.pred==salary)
    plot(glm.probs)
    boxplot(glm.probs)

Result of summary:

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-3.6016  -0.6337  -0.3539  -0.0786   3.3131  

Coefficients:
            Estimate Std. Error z value Pr(>|z|)    
(Intercept)    -1.433467   0.029795 -48.111  < 2e-16 ***
age             0.437952   0.026454  16.555  < 2e-16 ***
workclass      -0.104634   0.021628  -4.838 1.31e-06 ***
fnlwgt          0.052655   0.023348   2.255 0.024117 *  
education       0.055044   0.028739   1.915 0.055455 .  
education.num   0.851533   0.026941  31.607  < 2e-16 ***
marital.status -0.342673   0.026837 -12.769  < 2e-16 ***
occupation     -0.027290   0.023192  -1.177 0.239308    
relationship   -0.223131   0.033368  -6.687 2.28e-11 ***
race            0.100934   0.026330   3.833 0.000126 ***
sex             0.404090   0.034456  11.728  < 2e-16 ***
capital.gain    2.392861   0.108381  22.078  < 2e-16 ***
capital.loss    0.259485   0.019611  13.232  < 2e-16 ***
hours.per.week  0.335252   0.025005  13.407  < 2e-16 ***
native.country -0.005913   0.024925  -0.237 0.812480    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 16832  on 15080  degrees of freedom
Residual deviance: 11829  on 15066  degrees of freedom
AIC: 11859

Number of Fisher Scoring iterations: 7
$\endgroup$
  • $\begingroup$ Can you show your code? $\endgroup$ – Peter Flom - Reinstate Monica Mar 12 '14 at 17:21
  • $\begingroup$ Added the code... $\endgroup$ – Divi Mar 12 '14 at 17:29
1
$\begingroup$

I think what you might be looking for is the precision and recall measures, and the corresponding F score.

P = precision = # true positives / # predicted positives

R = recall = # true positives / # actual positives

F = 2PR/(P+R)

Here is a Coursera video that explains how these are used.

$\endgroup$
  • $\begingroup$ Added the result, still not sure how to interpret it! Please advise. $\endgroup$ – Divi Mar 12 '14 at 17:53
  • $\begingroup$ webdocs.cs.ualberta.ca/~eisner/measures.html... I guess this will work. Cleared by doubt! $\endgroup$ – Divi Mar 12 '14 at 17:59
  • $\begingroup$ Yes, that link spells out accuracy, as well. $\endgroup$ – John Yetter Mar 12 '14 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.