Logistic Trainer

Week 8 · from a probability to a yes/no decision · Summit Gear customer default
Built-in AI tutor. Stuck on odds, the sigmoid, or reading an odds ratio? Ask the helper on this page. It coaches with questions; it does not just hand you the answer.

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.

Part 1

A probability, and odds

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.

odds = p / (1 - p) # and back the other way: p = odds / (1 + odds)

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.

0.20
p = 0.20

What a log is, and why we take one

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.

Why bother with odds and logs. Logistic regression does not predict 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.
Part 2

The sigmoid squashes a score into a probability

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:

p = sigmoid(z) = 1 / (1 + e-z)

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.

0.0
The sigmoid gives you a probability for every customer. A probability is not yet a yes/no call. You still have to pick a cutoff: label it a predicted default when 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.
Part 3

The fitted model on Summit Gear default

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.

predictorcoefodds ratio
exp(coef)
directionreads 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.

Two terms that sound alike, kept separate. The odds from Part 1 describe one customer: that customer's 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.

Move one predictor, watch the predicted probability

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.

2
31
3.5
14

Pick a cutoff, read one confusion matrix

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.

0.50
predicted
pays (0)
predicted
default (1)
actual
pays (0)
1717true negative
45false positive
actual
default (1)
353false negative
85true positive
0.819accuracy
(right calls / all)
0.654precision
(of predicted defaults, share real)
0.194recall
(of real defaults, share caught)

Two reasons not to over-trust these numbers. First, every count here comes from the same 2,200 customers the model was fitted on, so the model is grading itself on answers it has already seen; on brand-new customers the numbers are usually a little worse. Testing fairly on customers held back from fitting is a Week 9 topic. Second, on a rare outcome accuracy is a misleading headline. About 80% of these customers pay, so a lazy rule that simply calls everyone "pays" would already be about 0.801 accurate while catching zero defaults, and the model's 0.819 is barely above that floor. The number worth watching is recall: of the customers who actually defaulted, the share the model flagged, which here is only 0.194.
Where this goes next. In Week 8 you read one model for direction and odds ratios, set one cutoff, and read one confusion matrix. Notice what 0.5 does here: it catches only a few real defaults (recall about 0.19), because defaults are only about one in five customers. Week 9 picks up exactly at that question: whether 0.5 is the right line, how to compare every possible cutoff at once with the ROC curve and AUC, and how to weigh a missed default against a false alarm in dollars. For now you do not need to find the best cutoff; just notice that moving it changes the matrix.

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.