I am trying to understand how logistic regression can use multiple variables to predict an outcome that is non-numeric. For example I have a titanic data set with 14 variables, 4 variables are strings, 4 are numeric, 2 are ints, and 4 are categorical factors. Now I use the built in logistic regression model in R to predict Surviving passengers (0 or 1 factor):

lr_model <- glm(Survived ~ int variable + categorical variable + ... different types of variables, data=trainData)

But when I predict on the new data .. I get numeric values returned, not 1,0 predictions like the Survived predictor should have modeled it. If I could get an explaination of how the model works on numeric and non numeric data that would clear things up, and if it does spit out numeric values, should I just write a function to see if it is higher than 0.5 to see if a given observation is Survived, and below 0.5 as they didn't survive?

Any thoughts?



Logistic regression predicts on odd-ratios or probability of success. In Wikipedia:

... whereas the output always takes values between zero and one

To predict 0 or 1, you will need to decide a threshold such as 0.5. If you try different thresholds, you may draw a ROC curve where you can decide your optimal threshold based on your preference on sensitivity and specificity.

  • $\begingroup$ +1. I'd add that the fact that logistic regression returns a probability -- which is often well-calibrated meaning is actually is a probability -- is very useful. $\endgroup$ – Wayne Jan 17 '17 at 2:56
  • $\begingroup$ @Wayne Yeah. I wrote "... or probability of success ....". It's actually the log-odds, but it can be converted. $\endgroup$ – SmallChess Jan 17 '17 at 2:56
  • $\begingroup$ Right, I'm just emphasizing that this is much more useful than something that just returned a 1 or 0 or some kind of ranking or something else. The OP is gaining more than they realize. $\endgroup$ – Wayne Jan 17 '17 at 2:57
  • $\begingroup$ @Student T -- If the logistic regression returns values above the 0,1 threshold, such as -2.34, 2.44, ect... Is this an error on my part when building the model, or is this also a part of the logistic regression model? $\endgroup$ – bmc Jan 17 '17 at 13:59
  • $\begingroup$ @bmc As I show from wikipedia, logistic regression always output between zero and one. It's a binary prediction algorithm. $\endgroup$ – SmallChess Jan 17 '17 at 14:01

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.