# Logistic Regression using Non Numeric data

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?

https://github.com/conradbm/data_science/blob/master/titanic_dataset/hw3/hw3_bmconrad.R

## 1 Answer

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.

• +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. – Wayne Jan 17 '17 at 2:56
• @Wayne Yeah. I wrote "... or probability of success ....". It's actually the log-odds, but it can be converted. – SmallChess Jan 17 '17 at 2:56
• 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. – Wayne Jan 17 '17 at 2:57
• @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? – bmc Jan 17 '17 at 13:59
• @bmc As I show from wikipedia, logistic regression always output between zero and one. It's a binary prediction algorithm. – SmallChess Jan 17 '17 at 14:01