Linear regression fails at binary outcomes. The logistic S-curve keeps predictions between 0 and 1. Adjust the curve, tune the threshold, and read the confusion matrix in real time.
Sign in to save your progress
When the outcome is binary (pass/fail), linear regression can predict impossible values outside [0, 1]. The logistic function solves this.
Linear Regression
Logistic Regression
Linear: Breaks the rules
Linear regression predicts negative probabilities and values above 1, both mathematically impossible for a probability.
Logistic: Stays bounded
The sigmoid function squashes any real-valued linear combination into the (0, 1) interval, always a valid probability.
Adjust the intercept and slope to explore how the logistic curve fits the data. The gold dot marks the 50% inflection point.
P(Pass) = 1 / (1 + e−(β₀ + β₁ × Hours))
= 1 / (1 + e−(-5.50 + 1.05 × Hours))Inflection point (50% probability): 5.24 hours
Points whose predicted probability is at or above the threshold are classified as PASS. Drag the slider to see how predictions change. Incorrect predictions are shown with an X mark.
True Pos (TP)
25
False Pos (FP)
4
True Neg (TN)
22
False Neg (FN)
9
All metrics update automatically as you adjust the threshold above. Notice that sensitivity and specificity trade off against each other.
Classification Metrics
Sensitivity
73.5%
Of actual passes, correctly caught 25 out of 34
Specificity
84.6%
Of actual fails, correctly rejected 22 out of 26
Precision
86.2%
Of predicted passes, fraction truly passed
F1 Score
0.794
Harmonic mean of precision and sensitivity
Confusion Matrix
| Actual PASS | Actual FAIL | |
|---|---|---|
| Predicted PASS | 25 True Positive | 4 False Positive |
| Predicted FAIL | 9 False Negative | 22 True Negative |
Adjust the threshold slider (Section 3) to see how the matrix changes in real time.
The coefficient β₁ tells us how the log-odds changes per unit increase in study hours.
Log-Odds Formula
log(p / (1−p))
= β₀ + β₁ × Hours
= -5.50 + 1.05 × Hours
β₁ (Slope)
1.050
Per-hour change in log-odds
Odds Ratio = e^β₁
2.858
Odds multiply by this each hour
Interpretation
For each additional study hour, the odds of passing multiply by 2.858. This represents a 186% increase in the odds of passing.
Common Misconception
An odds ratio of 2.858 does not mean the probability of passing is 2.858× higher. Odds and probability are different quantities. The odds ratio applies to the ratio p/(1−p), not to p itself.
A well-calibrated model: if it says 70% probability, roughly 70% of those cases actually pass. Points near the diagonal indicate good calibration.
On the diagonal
Predicted probability matches actual fraction. Perfect calibration.
Below diagonal
Model is overconfident: predicted too high relative to actual outcomes.
Above diagonal
Model is underconfident: actual rate exceeds the predicted probability.
Note: with only 60 data points and 5 bins, calibration estimates have high variance. Real-world calibration plots use larger datasets and often show confidence bands.
Sigmoid Function
σ(z) = 1/(1+e^−z). Maps any real number to (0,1). The S-shaped curve that gives logistic regression its name.
Maximum Likelihood
Logistic regression is fitted by maximizing the log-likelihood of observed outcomes, not by minimizing squared error.
Log-Odds (Logit)
The model is linear in the log-odds: log(p/(1−p)) = β₀ + β₁x. This is why it's called a generalized linear model.
Threshold Choice
The 0.5 default threshold is not always optimal. Use ROC curves or domain knowledge to pick the right trade-off for your context.