Mathwords logoMathwords

Logistic Regression — Definition, Formula & Example

Logistic regression is a method for predicting the probability of a yes-or-no outcome, such as pass/fail or sick/healthy, from one or more explanatory variables. Its predictions follow an S-shaped curve that always stays between 0 and 1.

For a binary response Y∈{0,1}Y \in \{0, 1\} with p=P(Y=1∣x)p = P(Y = 1 \mid x), logistic regression assumes the log-odds (logit) of pp is a linear function of the predictors: ln⁡p1−p=β0+β1x1+⋯+βkxk\ln\frac{p}{1-p} = \beta_0 + \beta_1 x_1 + \cdots + \beta_k x_k. The coefficients are estimated by maximum likelihood, not by least squares.

Key Formula

p=11+e−(b0+b1x)⟺ln⁡ ⁣(p1−p)=b0+b1xp = \frac{1}{1 + e^{-(b_0 + b_1 x)}} \quad\Longleftrightarrow\quad \ln\!\left(\frac{p}{1-p}\right) = b_0 + b_1 x
Where:
  • pp = Predicted probability that the outcome is a yes (Y = 1)
  • p1−p\frac{p}{1-p} = The odds of a yes
  • b0b_0 = Intercept: the log-odds of a yes when x = 0
  • b1b_1 = Slope: the change in log-odds for each 1-unit increase in x
  • xx = Explanatory (predictor) variable

Worked Example

Problem: A professor tracks 200 students. Of the 100 who attended a review session (x = 1), 75 passed the final. Of the 100 who did not attend (x = 0), 25 passed. Fit a logistic regression for the probability of passing. (With a single yes/no predictor, the maximum-likelihood fit reproduces each group's observed log-odds exactly.)
Step 1: Find the observed odds of passing in each group. Odds are passes divided by fails.
No session: 2575=13Session: 7525=3\text{No session: } \frac{25}{75} = \frac{1}{3} \qquad \text{Session: } \frac{75}{25} = 3
Step 2: Set the log-odds equal to the model in each group. At x = 0 the model gives the intercept. At x = 1 it gives the intercept plus the slope, so subtract to get the slope.
b0=ln⁡13≈−1.099,b1=ln⁡3−ln⁡13=ln⁡9≈2.197b_0 = \ln\tfrac{1}{3} \approx -1.099, \qquad b_1 = \ln 3 - \ln\tfrac{1}{3} = \ln 9 \approx 2.197
Step 3: Check by converting back to a probability for attendees. Since b₀ + b₁ = ln 3, the exponential term is 1/3.
p=11+e−ln⁡3=11+13=0.75p = \frac{1}{1 + e^{-\ln 3}} = \frac{1}{1 + \frac{1}{3}} = 0.75
Answer: The fitted model is ln⁡p1−p≈−1.099+2.197x\ln\frac{p}{1-p} \approx -1.099 + 2.197x. It returns the observed pass rates of 0.25 and 0.75, and the odds ratio eb1=9e^{b_1} = 9 means attendees had 9 times the odds of passing.

Why It Matters

Logistic regression is the standard tool in biostatistics and epidemiology for estimating how risk factors change the odds of a disease. Banks use it to score loan-default risk, and a single neuron with a sigmoid output in a neural network computes exactly this model.

Common Mistakes

Mistake: Fitting ordinary linear regression to a 0/1 outcome.
Correction: A straight line can predict probabilities below 0 or above 1, and its errors cannot have constant spread. The logit link in logistic regression keeps every prediction strictly between 0 and 1.

Related Terms