# Logistic regression and classification

> Logistic regression for yes/no outcomes such as churn or conversion: odds, the odds ratio, a decision threshold, and how to measure how good the predictions are.

- Course: [Statistics for Product Managers and Marketers](https://productovi.com/courses/statistics-for-pm-and-marketers.md)
- Module: Relationships
- Lesson 20/24, ~40 min
- Source: https://productovi.com/courses/statistics-for-pm-and-marketers/logistic-regression

## Logistic regression: when the outcome is yes or no

**Alex Tutor:** Everything we've predicted on CatChow's product team so far was a number: orders, revenue. But churn is yes or no. Can we still use a straight line?

**Sofia:** Sure, just fit a line where y is 1 for churned and 0 for stayed?

**Alex Tutor:** Try it, and the line happily predicts things like 1.3 or -0.2. Those aren't probabilities, and the relationship isn't a straight line near the edges anyway.

**Sofia:** So what do we use instead?

**Alex Tutor:** An S-shaped curve that's always squeezed between 0 and 1 — logistic regression.

![A cat in a shop doorway, between a full food bowl inside and the street outside, under a round gauge with a needle partway along its arc.](https://productovi.com/courses/statistics-for-pm-and-marketers/inline/logistic-regression-illustration-2.webp)

*The customer either stays or leaves, but the model gives a probability between those two ends.*

> **Exercise:** What's the main problem with fitting a plain linear regression to a yes/no outcome coded as 0 and 1?

## From probability to odds and log-odds

**Alex Tutor:** To build that curve, we first need a trick for turning a probability into something that can stretch from minus infinity to plus infinity.

**Alex Tutor:** Start with odds: the probability of the event divided by the probability that it doesn't happen.

$$
\text{odds} = \frac{p}{1-p}
$$

*Odds turn a 0-to-1 probability into a 0-to-infinity number: how many times more likely the event is than its opposite.*

**Sofia:** So if 80% of similar customers churn, the odds are... 4?

**Alex Tutor:** Exactly — 0.8 / 0.2 = 4. Odds of 4 mean churning is four times as likely as staying.

> **Exercise:** If the probability of a customer churning is 0.8, what are the odds of churning?

**Alex Tutor:** Odds still only go from 0 to infinity. Take the natural log of the odds, and now it's centred at zero and unbounded both ways.

$$
\ln(\text{odds}) = b_0 + b_1 x
$$

*Log-odds (the logit): this is the linear part logistic regression actually fits.*

**Sofia:** And that log-odds thing is what the regression actually predicts?

**Alex Tutor:** Right. Fit it just like linear regression, then run it back through a formula that squeezes it back into a 0-to-1 probability.

$$
p = \frac{1}{1 + e^{-(b_0 + b_1 x)}}
$$

*The logistic (sigmoid) function: steep in the middle, flat near 0 and 1.*

**Alex Tutor:** That's the whole trick: a straight line in log-odds space becomes a smooth S-curve in probability space.

![A cat slides down an S-shaped slide that is flat at the floor, flat at the top platform and steep in the middle.](https://productovi.com/courses/statistics-for-pm-and-marketers/inline/logistic-regression-illustration-3.webp)

*The S-curve never drops below the floor or rises above the ceiling, just like a probability.*

**Sofia:** Let's try it on an actual churn model.

> **Exercise:** CatChow's churn model is $\ln(\text{odds}) = -2 + 0.8 \times \text{months\_since\_last\_purchase}$. Predict the probability of churn for a customer with 3 months since their last purchase.

## How to interpret the odds ratio

**Alex Tutor:** About 60% churn risk at three months of silence. Let's talk about what that coefficient, 0.8, actually means.

**Sofia:** Each extra month adds 0.8 to something, right?

**Alex Tutor:** To the log-odds, yes. Undo the log, and it means each extra month multiplies the odds of churn by about $e^{0.8} \approx 2.23$ — not the probability itself.

> **Odds ratio**
>
> How many times the odds of the outcome change per one-unit increase in a predictor: exp() of that predictor's logistic regression coefficient.

**Sofia:** Isn't that the same as saying the probability goes up 2.23 times?

**Alex Tutor:** No — and that mix-up is common enough that it's your next question.

> **Exercise:** An odds ratio of 2.23 for a predictor means that each extra unit of the predictor doubles (roughly) the predicted *probability* of the outcome.

**Alex Tutor:** Let's see it in numbers. Take the customer at three months and add one more month of silence.

> **Exercise:** With $\ln(\text{odds}) = -2 + 0.8 \times \text{months}$, a customer silent for 3 months has a churn probability of about 0.60 (odds ≈ 1.49). Another month multiplies the odds by $e^{0.8} \approx 2.23$. What is the churn probability at 4 months?

## From probability to a decision

**Alex Tutor:** A probability is a number. To actually act — send a retention offer or not — you need a yes/no cutoff.

**Sofia:** 0.5, obviously? More likely than not means yes?

**Alex Tutor:** That's the default, but not always the smartest one. If a retention offer is cheap and a lost customer is expensive, you might flag anyone above 0.2.

> **Classification threshold**
>
> The predicted probability above which an observation is labelled positive. Often 0.5 by default, but tuned to how costly false positives and false negatives are.

**Sofia:** So the threshold is a business call, not a statistics one?

**Alex Tutor:** Both — statistics gives you the probability, and the business decides how cautious to be with it.

## Confusion matrix, precision and recall

**Alex Tutor:** Whatever threshold you pick, you'll want to score how good the resulting yes/no calls actually are.

**Alex Tutor:** Every prediction falls into one of four boxes, compared with what actually happened.

> **Confusion matrix**
>
> A 2x2 table: true positive (predicted churn, did churn), false positive (predicted churn, stayed), false negative (predicted stay, did churn), true negative (predicted stay, stayed).

> **Exercise:** Match each confusion-matrix cell to its meaning for a churn model.

**Alex Tutor:** Good. Two useful scores come straight out of that table: precision and recall.

**Alex Tutor:** Precision: of everyone you flagged as churning, what share actually churned. Recall: of everyone who actually churned, what share you caught.

**Sofia:** Why not just use accuracy — the share of all predictions that were right?

**Alex Tutor:** Because churn is rare. A model that just says "nobody churns" can score 95% accuracy while catching zero actual churners.

**Sofia:** Oh — so accuracy alone can lie to you.

**Alex Tutor:** Exactly. Before you compute anything, make sure you can say why.

> **Exercise:** Only 5% of CatChow subscribers churn in a month. A "model" that predicts "nobody churns" scores 95% accuracy. Which conclusion is **correct**?

**Alex Tutor:** Now precision on a model that does flag people.

> **Exercise:** A churn model's confusion matrix: 40 true positives, 10 false positives, 20 false negatives, 130 true negatives. Compute precision.

**Alex Tutor:** Nicely computed. Now here's the part that trips people up: precision and recall pull in opposite directions.

**Sofia:** Can't we just maximise both at once?

**Alex Tutor:** Rarely. Lower the threshold and you flag more people: recall climbs, but precision usually drops as false alarms creep in.

**Alex Tutor:** For a cheap retention email, that trade is often worth it — CatChow would rather email a few people who'd have stayed anyway than miss real churners.

![Two cats fishing: one small net holds a few orange fish, a wide net holds many orange fish plus several tin cans.](https://productovi.com/courses/statistics-for-pm-and-marketers/inline/logistic-regression-illustration-4.webp)

*A wider net catches more real churners, and more false alarms along with them.*

> **Exercise:** You lower the classification threshold for the churn model (flagging more customers as at risk). Which of these typically happen? Select all that apply.

## Before you set the threshold

**Alex Tutor:** Time to put this into words.

**Sofia:** What am I explaining this time?

**Alex Tutor:** A quick cost trade-off.

**Sofia:** Ready.

> **Exercise:** CatChow's churn model flags customers above a threshold for a \$5 retention email. A churned customer costs about \$150 in lost lifetime value on average. Would you want a higher or lower classification threshold, and why? Answer in 2-4 sentences.

**Alex Tutor:** Good instinct. Now the full case, one last time this module.

**Sofia:** Last one?

**Alex Tutor:** Last one — the churn model, the confusion matrix, and a real decision to recommend.

**Alex Tutor:** Here's the scenario.

> **Exercise:** Recommend whether CatChow should lower the churn model's classification threshold.

**Alex Tutor:** Great work. You've gone from a single scatter plot to a full churn model with a defensible threshold. Module 6 is next: turning models into forecasts and finding customer segments.

- Previous lesson: [Multiple linear regression](https://productovi.com/courses/statistics-for-pm-and-marketers/multiple-regression.md)
- Next lesson: [Models and forecasting](https://productovi.com/courses/statistics-for-pm-and-marketers/models-and-forecasts.md)

---
Productovi Learning. Free, no sign-up needed to read.
