A probability, then a decision
Logistic regression turns one measurement into a probability between 0 and 1. Here the measurement is how many practice questions a student completed. The outcome is passed or did not pass. The score is z = wx + b. The weight w says how much one extra question changes the score. The intercept b is the score at 0 questions. The probability is p = 1 / (1 + e^(−z)). A large positive score pushes p toward 1. A large negative score pushes p toward 0.
The starter model is w = 1 and b = −5. At 5 practice questions, z = 0 and p = 0.500. At 7 questions, Pat’s probability is 0.881. The threshold turns that probability into a class. Predict pass when p is at least the threshold. At 0.5, Pat is predicted to pass. At 0.9, Pat is predicted not to pass. The probability stays 0.881.
Some students with the same practice count had different outcomes, so the curve cannot be right for everyone. Kai passed after 2 questions, and the starter probability is 0.047. Bo also passed, after 4 questions, with probability 0.269. Both are predicted to fail at a threshold of 0.5. Binary cross-entropy for a student who passed is −log(p). Kai’s is 3.049. Bo’s is 1.313. The confident miss adds more to the loss. The model loss is the mean of the ten point losses, 0.956 at the start. Changing the threshold leaves every point loss, and the mean, unchanged.
Step training moves w and b once, in the direction that lowers that mean. Fit model repeats the step until the loss almost stops falling. Training cannot reach 0 here, because Ali did not pass and Kai passed after the same 2 questions.
Go deeper
For one student, the slope of the loss against the score z is p − y, where y is 1 for passed and 0 for did not pass. The weight’s slope multiplies that by the practice count. Each training step subtracts a fraction of the mean slope from w and from b. A probability of 0.1 for a student who passed has cross-entropy 2.303. A probability of 0.4 has cross-entropy 0.916. The threshold never enters that calculation.
| Student | Questions | Outcome |
|---|---|---|
| Mei | 1 | Did not pass |
| Ali | 2 | Did not pass |
| Kai | 2 | Passed |
| Jo | 4 | Did not pass |
| Bo | 4 | Passed |
| Sam | 6 | Did not pass |
| Lee | 6 | Passed |
| Pat | 7 | Passed |
| Noor | 8 | Did not pass |
| Ari | 9 | Passed |
Ali and Kai both completed 2 questions. Jo and Bo both completed 4. Sam and Lee both completed 6. The outcomes still differ.
Move the curve, then the threshold
Before you raise the threshold, guess which students who did not pass are still predicted to pass.
Probability, decision, then loss
The curve is the probability. The threshold is the decision. Training changes the curve.
Probability
z = wx + b becomes p = 1 / (1 + e^(−z)). The result stays between 0 and 1.
Threshold
Predict pass when p is at least the threshold. Moving it changes the decision, not the probability.
Cross-entropy
A confident wrong probability adds more than a near-threshold miss. Training steps downhill on the mean of those losses.