Loading the model

Logistic Regression Trainer

Week 11 · probability, odds and the sigmoid · reading odds ratios · one account's probability · a cutoff
AI tutor. The tutor on this page can see the sliders and what you type. It usually answers with a question, and it waits for your attempt before it confirms an answer.

Week 10 predicted a number: how many days each Summit Gear account takes to pay. This week the credit team asks a yes or no question about the same 2,200 accounts: will this account default? A model for a yes or no question should give back a probability, a number between 0 and 1, and logistic regression is a common way to estimate one. This page builds it in five steps: probability and odds, the curve that turns a score into a probability, reading the fitted coefficients, one account's probability, and the cutoff that turns a probability into a decision.

1 · Probability and odds

Probability, odds and log-odds

A probability p is a number from 0 to 1. 0 means it never happens, 1 means it always happens, and 0.20 means a 20% chance. 438 of Summit Gear's 2,200 accounts defaulted, about 20%, so that share (the base rate) is where a typical account starts.

Odds carry the same information written another way: the chance it happens divided by the chance it does not.

odds = p / (1 - p) and back again: p = odds / (1 + odds)

A probability of 0.20 is odds of 0.20 / 0.80 = 0.25, often said as 1 to 4: one default for every four accounts that do not default. A probability is boxed in between 0 and 1. Odds remove the ceiling, so they run from 0 up with no limit. Taking the log of the odds removes the floor as well, which gives the log-odds, a scale that runs from negative to positive with no limit at either end. Drag the slider and watch all three move together.

0.20

The three scales, lined up. The gray lines connect the same five accounts on each scale. Probability squeezes the extreme accounts against 0 and 1, while odds and log-odds spread them out. The log-odds scale has no floor or ceiling, so whatever the model's sum of terms comes to, it is a valid log-odds.

What a log is, and why we take one

A logarithm 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 × 10 = 100. 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 an account less likely to default than not (odds below 1) lands on a negative log-odds, an even-money account (odds of 1) lands on 0, and an account more likely to default lands on a positive number.

Why bother with odds and logs. Logistic regression does not predict p directly. It predicts the log-odds, because the log-odds can be any number, positive or negative, which is what a sum of coefficient × predictor terms produces. The model works in log-odds and converts back to a probability at the end. That conversion is the sigmoid, in step 2.

Your turn

Credit puts an account's probability of default at 0.25. What are its odds of default? Type a number. A fraction such as 2/5 works too.

2 · The sigmoid

The sigmoid

The model adds up intercept + coefficient₁ × x₁ + coefficient₂ × x₂ + ... into one number called the score z. The score is the log-odds, so it 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. A large positive score pushes p toward 1, and a large negative score pushes it toward 0. It never quite reaches either end, which gives the S shape. Move z and watch the dot ride the curve.

0.0
The sigmoid gives every account a probability, but credit still needs a yes or no. A cutoff turns one into the other: flag the account when p is at or above the cutoff, otherwise let it through. Many tools use 0.5 unless you set something else, though a better cutoff usually depends on what each kind of mistake costs. You set a cutoff in step 5, and the next page, the cutoff and cost trainer, shows how to choose one.
3 · Read the fit

Odds ratios

Here is a logistic regression already fitted on the Summit Gear table, target defaulted (1 if the account's receivable was written off as uncollectible). It is the deck's model: four predictors, fit on 1,760 of the accounts, with the other 440 held back so it can be tested on accounts it never saw (step 5). This step reads the fitted coefficients the way you would read output a colleague or an AI assistant hands you.

A coefficient is the change in the log-odds of default for a one-unit rise in that predictor, holding the other predictors fixed. Raise e to the coefficient, exp(coefficient) in Python or =EXP() in Excel, and you get the odds ratio: the number the odds get multiplied by for that one-unit rise. Above 1 raises the odds of default, below 1 lowers them, and exactly 1 means no change.

predictorcoefficientodds ratio per unita realistic change: odds multiplied by
Loading the model

The bars show what the realistic change in the last column does to the odds, on a scale where 1 means no change. Bars to the right raise the odds of default, bars to the left lower them.

Odds and an odds ratio are two different things. Loading the worked example.
Units matter. Loading.

If you took an earlier analytics course that read logistic coefficients as marginal effects (the change in probability for a one-unit rise), both readings are valid. This course uses odds ratios because one number holds for every account, while a marginal effect changes with where the account sits on the curve. These are point estimates from one sample, so an odds ratio close to 1 may not be distinguishable from no effect. Read the direction and the rough size, and check the p-value column in the full output before leaning on a small one.

4 · One account

From an account's columns to a probability

Pick values for the four columns and watch the model build this account's probability. The score starts at the intercept, and each predictor adds its coefficient times its value. The sigmoid then turns the score into a probability. The sliders start at the median account: the middle value of each column across the 1,760 training accounts.

2
31
3.5
14

Predict first: two more late invoices

Loading the model.

5 · A cutoff

From a probability to a decision: pick a cutoff

The model gives every account a probability. Credit needs a yes or no: review this account before its next order ships on terms, or let it through. A cutoff turns one into the other: flag an account for review when its probability is at or above the cutoff. The slider starts at 0.5 because many tools use it unless you set something else, and the next page shows how the cost of each kind of mistake can move the cutoff away from it.

These are the 440 held-out accounts, the ones the model never saw while it was fit. Each square is one account, placed by its predicted probability. Accounts that did not default sit above the axis and accounts that defaulted sit below it. Move the cutoff and every square to its right is flagged. The color says which cell of the confusion matrix (the table of right and wrong calls) the account lands in.

0.50

Which cutoff to use depends on what each mistake costs. The cutoff and cost trainer puts precision, recall, the dollar cost of every cutoff and the ROC curve on these same 440 accounts.

Open the cutoff and cost trainer
6 · Your reading

Read the odds ratio in credit terms

One or two sentences on prior_late_count, in your own words, for a credit analyst. Say what the odds ratio multiplies, by about how much, and what is held fixed. The check below is a fixed set of rules, not a grade, and the tutor will ask you to try before it confirms a reading.

Checks the framing and the size of the multiplier, not the wording.