What is logistic regression?
Last updated: 2026-11-23
Logistic regression predicts the probability of a yes-or-no outcome from one or more numbers. It fits a straight line to the log-odds of the outcome, then converts the result back to a probability between 0 and 1 with an S-shaped curve called the logistic function.
Start learning No account needed
If you have met linear regression, the line-fitting idea is the same, and the new part is the step between probabilities, odds and log-odds.
1. Logistic regression in plain words
Say each student either passes or fails, and you want the chance of passing given the hours studied. A straight line is a poor fit for that, because a probability has to stay between 0 and 1 and a line keeps going. So logistic regression works on a quantity that can take any value. The probability of passing is p. The odds are p / (1 - p), so a probability of 0.75 is odds of 3, or 3 to 1. The log-odds are the natural log of the odds.
The model says the log-odds are a straight line in the number you know: ln(p / (1 - p)) = a + b × x. Solving for p gives p = 1 / (1 + e-(a + b × x)), which is the logistic function, and it stays between 0 and 1 for any x. There is no short formula for a and b like the one in linear regression. They are chosen by maximum likelihood, which means the values that make the passes and fails you observed as probable as possible under the model, and a computer finds them by repeated adjustment.
To turn a probability into a yes or no, pick a cutoff, often 0.5, and predict pass when p is at or above it.
2. A worked example: 6 students, hours studied and pass or fail
The numbers below are made up for this page. Each student has a number of hours studied (x) and an outcome, 1 for pass and 0 for fail.
| Hours (x) | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|
| Passed (y) | 0 | 0 | 1 | 0 | 1 | 1 |
Maximum likelihood gives an intercept a = -4.249 and a slope b = 1.214 for the log-odds. These come from the script, since there is no formula to do by hand. Everything after that is arithmetic you can check. Here is each student's log-odds, converted to odds and then to a probability.
| Hours | Log-odds a + b × x | Odds | Probability p | Predicted at 0.5 | Actual |
|---|---|---|---|---|---|
| 1 | -3.035 | 0.048 | 0.046 | fail | fail |
| 2 | -1.821 | 0.162 | 0.139 | fail | fail |
| 3 | -0.607 | 0.545 | 0.353 | fail | pass |
| 4 | +0.607 | 1.835 | 0.647 | pass | fail |
| 5 | +1.821 | 6.178 | 0.861 | pass | pass |
| 6 | +3.035 | 20.802 | 0.954 | pass | pass |
Read the slope first. One more hour adds 1.214 to the log-odds, which multiplies the odds by e1.214 = 3.37. That multiplier is the odds ratio. You can see it in the table: the odds go from 0.545 at 3 hours to 1.835 at 4 hours, and 1.835 / 0.545 = 3.37, the same as between any other two neighboring hours.
Now the cutoff. A probability of 0.5 means odds of 1 and log-odds of 0, so the boundary is where -4.249 + 1.214 × x = 0, which is x = 3.5 hours. Students at 4 hours or more are predicted to pass. The rule gets 4 of the 6 students right. It misses the student at 3 hours who passed (p = 0.353) and the student at 4 hours who failed (p = 0.647), which is what you expect from six points where the outcomes overlap.
Now predict a new student who studied 4.5 hours. The log-odds are -4.249 + 1.214 × 4.5 = 1.214, so the odds are 3.37, and p = 3.37 / (1 + 3.37) = 0.771. That is above 0.5, so the prediction is pass, with a probability of about 77 percent.
Output from the script, run on 2026-11-23: intercept a = -4.2491, slope b = 1.2140, odds ratio per hour = exp(b) = 3.367, cutoff 0.5 at a + b*x = 0, x = 3.500 hours and 4.5 hours: log-odds 1.214, odds 3.367, p = 0.771. These come from a short script, logistic-regression-example.mjs, that runs the fit and prints the table.
3. A common misconception: the coefficient is the change in probability
It is tempting to read the slope of 1.214 the way you read a slope in linear regression, as how much the chance of passing rises per hour. It is not. The coefficient is a change in log-odds, and the odds ratio of 3.37 multiplies the odds. How much the probability moves depends on where you start.
Here are the same one-hour steps in our example. From 2 to 3 hours, p goes from 0.139 to 0.353, a rise of +0.213. From 3 to 4 hours it goes from 0.353 to 0.647, a rise of +0.295. From 5 to 6 hours it goes from 0.861 to 0.954, a rise of +0.093. The odds ratio is 3.37 in all three cases, and the probability changes by three different amounts, because a probability cannot go past 1 and the curve flattens near the ends.
The same care applies to the wording. An odds ratio of 3.37 means the odds are 3.37 times as large, and that is not the same as the probability being 3.37 times as large. From 3 to 4 hours the probability goes up by 0.647 / 0.353 = 1.83 times. The slope also describes how hours and passing move together in this data, and it does not show that more hours cause a pass.
4. Test yourself
Close this page and explain, to someone else or to an empty room, what the odds ratio of 3.37 means in the hours and passing example, and why the probability rises by +0.295 from 3 to 4 hours but only +0.093 from 5 to 6 hours. Then reopen the page and compare. The first place your explanation drifted is the part to study again.
If the line-fitting part felt unfamiliar, what is linear regression works through it with its own numbers. For the general method, see how to test yourself.
What the sources found, and their limits
An Introduction to Statistical Learning, section 4.3. Gareth James, Daniela Witten, Trevor Hastie and Robert Tibshirani, first edition, seventh printing, free from the authors. It supports the logistic function, the odds p / (1 - p), the log-odds (logit) being linear in x, a one-unit increase in x changing the log-odds by the coefficient and multiplying the odds by e to the coefficient, the coefficient not being the change in probability because that change depends on the current value of x, and fitting by maximum likelihood. It also supports the problem with a straight line, which can give probabilities below 0 or above 1. Source: Chapter 4, Classification, read on 2026-11-23. Limits: the book's example of moving a probability threshold away from 0.5 uses discriminant analysis, and we apply the same idea to the logistic cutoff. The 6 students, their hours and their outcomes are ours, made up to show the arithmetic. Six points are enough to show the steps, and too few to trust the fitted numbers for anything else.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.
Bring a topic you are studying, such as what an odds ratio means. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, such as a term, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of giving the final answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through.
It does not read or mark a written answer, and it does not write your explanation for you, so the explanation has to be yours. You must be 18 or older, and conversations are deleted after 7 days.
FAQ
Why not use linear regression for a pass or fail outcome? A straight line has no ceiling or floor, so it can predict a probability outside 0 to 1. In our example, a straight-line fit to the six 0 and 1 outcomes (slope 0.2, intercept -0.2) predicts 1.20 at 7 hours, which is not a probability. The logistic fit predicts 0.986 at 7 hours, and it stays between 0 and 1 at any number of hours.
Does the cutoff have to be 0.5? No. The model gives a probability, and the cutoff is a separate choice about when to say pass. In our example, a cutoff of 0.5 puts the boundary at 3.5 hours, and a cutoff of 0.8 moves it to 4.64 hours, so fewer students are predicted to pass. A higher cutoff is a stricter rule for saying pass, and which one suits you depends on how costly each kind of miss is.
Start with what you're working on
Tell the tutor which topic you are studying and let it ask you the questions.
Start learning No account needed
See also: all study guides