Skip to content

Cheatsheet: From a line to a probability: logistic regression

StepFormulaRole
1. Linear partz = intercept + coefficient * featuresame weighted sum as linear regression
2. Squashprobability = sigmoid(z)bend z into the range 0 to 1
Input zOutput (probability)
very negativenear 0
-2about 0.12
0exactly 0.50
2about 0.88
very positivenear 1
ConceptRule
Decision (threshold 0.5)probability >= 0.5 -> yes, else no
Equivalent testz >= 0 -> yes (same thing)
Decision boundarywhere probability = 0.5, i.e. where z = 0
Boundary shapea straight line or flat surface

Worked example (pass an exam from hours studied)

Section titled “Worked example (pass an exam from hours studied)”
hoursz = -4 + hoursprobabilitydecision
2-2~0.12FAIL
400.50on the fence (boundary)
62~0.88PASS
ItemNote
How it is fitgradient descent (no closed-form formula)
Lossrewards confident-correct, punishes confident-wrong
Positive coefficientpushes probability of “yes” up
Negative coefficientpushes probability of “yes” down
PitfallReality
”Regression predicts a number”it is a classifier; output is a probability
Probability is exact truthit is a model estimate; can be confidently wrong
0.5 is the only thresholdmove it when error costs are unequal
Boundary can curveit is straight; curved data needs engineered features