NeuroNomixer logoNeuroNomixer
  • Home
  • Blog
  • Visual Guides
  • Authors
  • Contact
Sign InSign Up
NeuroNomixer logo
HomeBlogAuthorsContactPrivacy Policy

© 2026 NeuroNomixer — Built with Next.js & Tailwind CSS

Visual Guides/Logistic Regression
UNIT 11: GENERALIZED MODELS

Logistic Regression: Predicting Yes or No

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.

Linear vs logistic comparison viewed
Threshold adjusted
Sensitivity/specificity trade-off observed
Odds ratio interpreted
Calibration plot examined

Sign in to save your progress

1. The Problem with Linear Regression

When the outcome is binary (pass/fail), linear regression can predict impossible values outside [0, 1]. The logistic function solves this.

Linear Regression

Impossible!Impossible!00.250.50.7510246810Study HoursP(Pass)Linear fit

Logistic Regression

00.250.50.7510246810Study HoursP(Pass)Logistic S-curveStays within [0,1]

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.

2. Shape the S-Curve

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))
00.250.50.751024681050% @ 5.2hStudy HoursP(Pass)
Intercept (β₀)-5.50
Slope (β₁)1.05

Inflection point (50% probability): 5.24 hours

3. Choose a Decision Threshold

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.

00.250.50.751024681050%Study HoursP(Pass)
Decision Threshold: 50%0.50

True Pos (TP)

25

False Pos (FP)

4

True Neg (TN)

22

False Neg (FN)

9

Teal = PASS classRed = FAIL class✕Wrong prediction

4. Performance Metrics

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

Accuracy78.3%

Confusion Matrix

Actual PASSActual 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.

5. Odds Ratio & Interpretation

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.

6. Calibration Plot

A well-calibrated model: if it says 70% probability, roughly 70% of those cases actually pass. Points near the diagonal indicate good calibration.

0.00.00.20.20.40.40.60.60.80.81.01.0Perfect16%43%67%71%94%Mean Predicted ProbabilityActual Fraction Passed

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.

Key Concepts

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.

← Regression DiagnosticsCount Models: Poisson →