Last time the target was a number: how many days a customer takes to pay. This time the
question is yes or no — will this receivable go bad. A regression that predicts a dollar amount cannot
answer a yes/no question. What we want instead is a probability — a number between 0 and 1 — and a
model that produces one. That model is logistic regression. Three short steps below: first what a
probability and odds even are, then the curve that turns a score into a probability, then the fitted model on
Summit Gear's defaulted column.
Nothing earlier in the course needed this, so start from the ground. A probability
p is just a number from 0 to 1: 0 means it never happens, 1 means it always happens, 0.5 is a
coin flip. A 20% chance of default is p = 0.20.
Odds are the same information written a different way: the chance it happens divided by the chance it does not.
A probability of 0.20 is odds of 0.20 / 0.80 = 0.25,
often said as "1 to 4", meaning one default for every four customers that pay. A probability is boxed into 0 to
1; taking the odds removes the ceiling, so odds run from 0 up to infinity. The log step, which removes the floor
and lets the scale go negative, gets its own short explanation just below. Drag the slider and watch the
probability, the odds, and the log-odds move together.
A logarithm sounds technical, but it answers a plain question: what power do you raise a
base number to in order to reach this value. With base 10, log(100) = 2 because 10² =
100, and log(1000) = 3. Logistic regression uses the natural log, written
ln, which asks the same question with the fixed number e ≈ 2.718 in place of 10. The
base does not change the idea.
Three facts are all you need here. The log of 1 is exactly 0. The log of a number bigger than 1 is positive. The log of a number between 0 and 1 is negative. So when you take the log of the odds, a customer likely to pay (odds below 1) lands on a negative number, an even-money customer (odds of 1) lands on 0, and a customer likely to default (odds above 1) lands on a positive number. That is how the odds, which only ran from 0 upward, get stretched onto a scale that runs from deeply negative to deeply positive. That stretched scale is the log-odds, and it is the scale a linear model can actually work on.
p
directly. It predicts the log-odds, because (as you just saw) log-odds can be any number, positive or
negative, which is exactly what a sum of (coefficient × predictor) terms produces. The model works
in log-odds, then converts back to a probability at the very end. That conversion is the sigmoid, next.The model adds up intercept + coef₁·x₁ + coef₂·x₂ + … into a single number
called the linear score z (this is the log-odds). z can be anything from
deeply negative to deeply positive. The sigmoid function bends that whole range into the 0-to-1 band a
probability lives in:
When z = 0 the probability is exactly 0.5. Large
positive z pushes p toward 1; large negative z pushes it toward 0. It
never quite reaches either end, which gives the S-shaped curve. Move z and watch the dot ride the
curve, then read the plain-language sentence below it.
p is at or above
the line, otherwise not. A common starting line is 0.5, but in practice the cutoff is a risk-informed business
decision: leadership weighs the cost of a missed default against the cost of a false alarm and sets the line
accordingly. You will set that cutoff yourself in Part 3.Here is a logistic regression already fitted on the summit_gear_customers table,
target defaulted (1 = the receivable went bad). The AI wrote and ran the fit; your job is to
read it. Two things to read from every logistic model: the direction of each coefficient, and
its odds ratio exp(coef) — the multiplier on the odds of default for a one-unit rise in
that predictor, holding the others fixed.
| predictor | coef | odds ratio exp(coef) | direction | reads as |
|---|
Base default rate in the data is about 20%. Intercept (the log-odds for
a baseline customer) = -3.26. An odds ratio above 1 raises default risk, below 1 lowers it; an
odds ratio of exactly 1 means the predictor does nothing.
These coefficients and odds ratios are point estimates — single
best-guess numbers with no confidence interval attached — so an odds ratio close to 1 should not be read as a
real effect; it could just as easily be noise. Read direction and rough magnitude, and treat a near-1 ratio as
not established. Using exp(coef) odds ratios here is a deliberate choice; an earlier version of this
course read logistic coefficients as marginal effects instead — both are valid, and the odds ratio still
multiplies the odds, not the probability.
p / (1 - p). An odds ratio describes a predictor: it is the factor
exp(coef) by which a one-unit increase in that predictor multiplies a customer's odds, with the
other predictors held fixed. Worked through on the largest effect here, prior_late_count has a
coefficient of +0.624, so its odds ratio is exp(0.624) ≈ 1.87. Each additional prior
late payment therefore multiplies a customer's odds of default by about 1.87, an increase of roughly 87 percent
in the odds. Because the multiplier acts on the odds and not on the probability directly, the predicted
probability below follows a curve rather than a straight line.This is one Summit Gear customer sitting at typical values for everything else. Slide a predictor and watch this customer's predicted probability of default update through the same sigmoid you saw in Part 2. The biggest mover is prior late payments, so try that slider first. A plain-language sentence under the sliders explains what you are looking at as you move them.
The model gives all 2,200 customers a probability. To turn those into yes/no calls you choose a cutoff: predict default when the probability is at or above the line. Move the cutoff and read the one resulting confusion matrix, how many of the actual outcomes the model gets right and wrong. The indicator under the slider tells you where you are relative to the standard 0.5 line. Start at 0.5.
Before you ask the tutor, jot your own one-line read of the
prior_late_count odds ratio (about 1.87) and what the 0.5 confusion matrix says about
trusting this model as-is. The tutor reacts to what you write rather than answering for you.