Logistic Regression
For a yes-or-no outcome, a straight line would eventually predict probabilities below 0 or above 1, which make no sense. Logistic regression fixes that by fitting the line to the log-odds instead, then bending it into an S-curve that always stays between 0 and 1.
What the symbols mean
- Probability of yes
The predicted chance the outcome happens.
- Slope
Each 1-unit increase in x multiplies the odds by e^(b₁).
- Intercept
Sets where the curve crosses p = 0.5.
- Log-odds
The logarithm of the odds p/(1 − p); this is what's linear in x.
Explanation
Logistic regression is simply a way to predict the chance of a yes-or-no outcome, like whether a loan defaults, from some measurement. It's named after the logistic function, the S-shaped curve it uses. The first formula looks scary, but read it inside out: (an ordinary straight line, just like the last few lessons), plugged into (a squashing step that turns any number into something between 0 and 1). The second formula says the same thing backward: the log-odds (a way of rescaling probability, explained next) is a straight line in . It's a line in disguise, so bear with the notation.
Why not just a line? Suppose you fit an ordinary regression line to 0s and 1s. Out at large it keeps climbing past 1, and at small it dips below 0, predicting a 120% or a −15% chance. Probabilities are stuck between 0 and 1, so we need to stretch them onto a scale that runs all the way from to , fit the line there, and then squash back.
Odds. That stretching happens in two steps. If , the odds are (4 to 1). Odds run from 0 to infinity, and taking the log stretches that to to , so a line can model log-odds. The sigmoid is just that process undone, which is why the curve has its S shape.
The 50% point is where , at . That's where the odds are 1 to 1, so the log-odds are 0.
Fitting. The coefficients are chosen to maximize the likelihood of the observed yes/no outcomes (there's no closed form, so software iterates). The model is the simplest neural network: one neuron with a sigmoid activation.
A common mistake. It's tempting to read like an ordinary slope, as "the probability goes up by per unit of ." It doesn't. is the change in the log-odds. On the odds it acts as a multiplier, per unit of , and the change in probability itself depends on where you are on the S-curve: big in the middle, tiny near 0 or 1.
See it
Worked examples
A model has , . Find at .
- 1
First the straight-line part, the log-odds: .
Practice
Type your answer and check it. Solve them all to complete the lesson.
With , , find at .
Find at .
What are the odds when ?
For , , at what is ?
Increasing by 1 multiplies the odds by what factor (with )?
A credit model says the log-odds of default are , where is the debt-to-income ratio in percent. What is the probability of default at ?
At what debt-to-income ratio does the default probability reach 50%?
The hardest one here. Get it, and you've got this lesson.
By what factor do the odds of default multiply for each extra 10 points of debt-to-income ratio?
Where it's used
Credit scoring, spam detection, disease risk models and click prediction all use logistic regression, and it's the output layer of most classification neural networks.