Sub topic 12
Reading coefficients as log-odds and odds ratios
This chapter assumes you can fit a logistic regression with scikit-learn, and that you know the sigmoid and the link between probability, odds, and log-odds from earlier chapters. Here you learn what a fitted coefficient says, how to turn it into an odds ratio, and where that reading breaks down.
The model is linear in log-odds
Logistic regression assumes the log-odds of the positive class is a linear function of the features:
log(p / (1 − p)) = b + w₁x₁ + w₂x₂ + … + wdxd
Each coefficient therefore has a direct meaning. Increasing feature xⱼ by one unit, with all other features held fixed, adds wⱼ to the log-odds. Exponentiating both sides gives the same statement in terms of odds. The odds are multiplied by exp(wⱼ). That multiplier is the odds ratio for feature j.
| Coefficient wⱼ | Odds ratio exp(wⱼ) | Effect of a one-unit increase |
|---|---|---|
| 0 | 1.00 | No change in the odds |
| 0.7 | about 2.01 | Odds roughly double |
| −0.7 | about 0.50 | Odds roughly halve |
| 2.3 | about 10 | Odds multiplied by ten |
Two facts follow. The sign of the coefficient gives the direction of the effect. The odds ratio is the same wherever you start on the feature's range, because the model is additive in log-odds.
An odds ratio is not a probability change
The most common misreading treats "odds double" as "probability doubles". The same odds ratio produces different probability shifts depending on where you start.
Suppose exp(w) = 2.
| Starting p | Starting odds | New odds | New p | Change in p |
|---|---|---|---|---|
| 0.10 | 0.111 | 0.222 | 0.182 | +0.082 |
| 0.50 | 1.000 | 2.000 | 0.667 | +0.167 |
| 0.90 | 9.000 | 18.000 | 0.947 | +0.047 |
The effect on probability is largest near p = 0.5 and shrinks toward 0 and 1. This follows from the sigmoid's slope, which is p(1 − p). If a stakeholder needs a probability, compute it with the full model for a concrete example. Do not quote the odds ratio as a probability.
For rare outcomes (p small), the odds are close to the probability, so an odds ratio of 2 is roughly a doubling of the probability. This approximation fails when the outcome is common.
Units and scaling decide what you can compare
A coefficient is expressed per unit of its feature. A coefficient on "income in dollars" and one on "age in years" are on different scales, so comparing their sizes tells you little.
If you standardize features (subtract the mean, divide by the standard deviation), every coefficient becomes the change in log-odds per one standard deviation. Magnitudes are then roughly comparable across features. This is one reason scaling matters even when the optimizer would converge without it.
You can convert back to raw units. If the scaler divides by σⱼ, then the coefficient per raw unit is wⱼ / σⱼ. The intercept also shifts, but you only need the slopes for odds ratios.
The code below fits a pipeline and reports odds ratios in both standardized and raw units. It is self-contained.
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
data = load_breast_cancer()
X, y = data.data, data.target
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, stratify=y, random_state=0
)
model = make_pipeline(StandardScaler(), LogisticRegression(C=1.0, max_iter=1000))
model.fit(X_train, y_train)
clf = model.named_steps["logisticregression"]
scaler = model.named_steps["standardscaler"]
w_std = clf.coef_[0]
w_raw = w_std / scaler.scale_
print("Positive class:", clf.classes_[1], "-> target name:", data.target_names[1])
top = np.argsort(np.abs(w_std))[::-1][:3]
for i in top:
print(
f"{data.feature_names[i]:<25} "
f"coef/SD={w_std[i]:+.2f} OR/SD={np.exp(w_std[i]):.3f} "
f"OR/raw unit={np.exp(w_raw[i]):.3f}"
)In this dataset the positive class (label 1) is "benign". A negative coefficient therefore means higher values of that feature lower the odds of benign, which raises the odds of malignant. Always check clf.classes_ before interpreting signs. Flipping the label encoding flips every coefficient's sign and inverts every odds ratio.
Reading an odds ratio below 1
An odds ratio of 0.40 is a 60% reduction in the odds. It is often easier to invert it: 1 / 0.40 = 2.5, so the odds are 2.5 times higher for a one-unit decrease. Both statements are equivalent. Choose the one that matches how your audience thinks.
Conditions that make the reading valid
The statements above hold only under certain conditions. Check each one before reporting results.
- "Holding the others fixed" must be possible. If two features are strongly correlated, such as radius and perimeter in this dataset, you rarely see one change without the other. Their individual coefficients become unstable and can take opposite signs, even though the model predicts well.
- Regularization biases coefficients toward zero. With a small
C, the odds ratios are shrunk and are not unbiased estimates of effect sizes. Treat them as a description of the fitted model, not of the world. - The effect is assumed constant on the log-odds scale. If the true relationship is curved, one coefficient averages over it. Add a transformed or squared term if you suspect this.
- Interactions change the meaning. If the model includes a product term such as x₁·x₂, the effect of x₁ depends on x₂, and the main-effect coefficient alone is no longer the whole story.
- Association is not causation. The coefficient describes how the outcome differs across feature values in your data. It does not say what happens if you intervene on that feature.
- Perfect separation breaks it. If a feature separates the classes completely, the unregularized coefficient grows without bound and its odds ratio is meaningless.
scikit-learn does not report standard errors or confidence intervals for coefficients. If you need them, use statsmodels.Logit, or resample your training data with the bootstrap and refit.
Summary of the reading procedure
- Confirm which class is positive using
clf.classes_. - Check whether features were scaled, and note the unit of each coefficient.
- Report the coefficient as a change in log-odds, or exponentiate it for an odds ratio.
- For probability statements, compute predictions at a specific baseline.
- Check for correlated features, strong regularization, and separation before trusting any single value.
Exercise
A logistic regression is fitted on standardized features. The coefficient for "number of late payments" is 0.40, and the outcome is "customer defaults". A customer currently has a predicted default probability of 0.20. If their late payments rise by one standard deviation and nothing else changes, what is the new predicted probability? State the odds ratio too.
Show answer
The odds ratio is exp(0.40) ≈ 1.49. The starting odds are 0.20 / 0.80 = 0.25. The new odds are 0.25 × 1.49 ≈ 0.373. The new probability is 0.373 / (1 + 0.373) ≈ 0.27. The probability rises by about 7 percentage points, which is smaller than a 49% rise in probability would imply.