2.2.16Linear & Logistic Regression

Interpreting model coefficients

1,705 words8 min readdifficulty · medium

WHY do we care about coefficients at all?

We don't just want a black box that predicts. We want to understand: which features matter, in which direction, and by how much. A coefficient βj\beta_j is the model's estimated slope along feature xjx_j. Interpreting it correctly is the difference between "smoking increases risk" and a meaningless number.


WHAT does a LINEAR regression coefficient mean?

Model: y^=β0+β1x1++βpxp\hat{y} = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p.

Derivation of interpretation (from scratch). Take the prediction at xjx_j and at xj+1x_j + 1 (everything else fixed):

y^(xj+1)y^(xj)=[β0++βj(xj+1)+][β0++βjxj+]=βj.\hat{y}(x_j+1) - \hat{y}(x_j) = \big[\beta_0 + \dots + \beta_j(x_j+1) + \dots\big] - \big[\beta_0 + \dots + \beta_j x_j + \dots\big] = \beta_j.

  • Intercept β0\beta_0: predicted yy when all features are 0 (often meaningless if x=0x=0 is out of range — that's why we sometimes center features).

WHAT does a LOGISTIC regression coefficient mean?

Logistic regression models log-odds, not probability:

log ⁣(p1p)=β0+β1x1++βpxp,p=P(y=1x).\log\!\left(\frac{p}{1-p}\right) = \beta_0 + \beta_1 x_1 + \dots + \beta_p x_p, \qquad p = P(y=1\mid x).

Derivation of the odds-ratio interpretation. The log-odds is linear, so as before:

log-odds(xj+1)log-odds(xj)=βj.\text{log-odds}(x_j+1) - \text{log-odds}(x_j) = \beta_j.

Exponentiate both sides. Let odds=p1p\text{odds}=\frac{p}{1-p}:

odds(xj+1)odds(xj)=eβj.\frac{\text{odds}(x_j+1)}{\text{odds}(x_j)} = e^{\beta_j}.

Figure — Interpreting model coefficients

HOW to compare coefficients: standardization

You cannot say "β1>β2\beta_1 > \beta_2 so feature 1 is more important" if the features are on different scales (income in $ vs. age in years). A tiny coefficient on income might dominate because income values are huge.

Why βjstd=βjσj\beta_j^{\text{std}} = \beta_j\sigma_j? If zj=xj/σjz_j = x_j/\sigma_j (roughly), then a 1-unit change in zjz_j is a σj\sigma_j-unit change in xjx_j, giving βjσj\beta_j\sigma_j change in yy.


Common mistakes (Steel-manned)


Active recall

Recall Test yourself (hidden)
  1. In linear regression, what does βj\beta_j literally measure?
  2. Why must we say "holding others fixed"?
  3. What quantity does a logistic β\beta change linearly?
  4. How do you turn a logistic β\beta into an odds ratio?
  5. Why standardize before comparing coefficient sizes?
  6. Why can correlated features make coefficients untrustworthy?
Recall Feynman: explain to a 12-year-old

Imagine a recipe machine. Each ingredient has a "power number." In the price machine, the power number says how many dollars one more cup of that ingredient adds — but only if you don't change anything else. In the yes/no machine (will it rain?), the power number is trickier: you have to press the "e" button on it (eβe^\beta), and it tells you how many times more likely the "yes" becomes. If two ingredients are measured in different-sized cups (teaspoons vs. buckets), you can't compare their power numbers until you use the same cup — that's standardizing.


Connections


Linear regression: what does coefficient βj\beta_j mean?
The change in predicted yy (in units of yy) per 1-unit increase in xjx_j, holding all other features fixed.
Why the phrase "holding other features fixed"?
Because βj\beta_j is a partial effect; other features may move together in reality (correlation), so isolating one is an idealization.
Logistic regression: what does βj\beta_j change linearly?
The log-odds, logp1p\log\frac{p}{1-p}, not the probability.
How to convert a logistic coefficient to an odds ratio?
Exponentiate it: odds ratio =eβj= e^{\beta_j}; each unit increase in xjx_j multiplies the odds by eβje^{\beta_j}.
βj=0\beta_j=0 in logistic regression means what for the odds?
e0=1e^0=1, so the feature multiplies the odds by 1 — no effect.
Why can't you compare raw coefficient magnitudes for feature importance?
They depend on feature units/scale; a feature with large numeric range gets a small coefficient and vice versa.
How do you make coefficients comparable?
Standardize features (subtract mean, divide by SD); use βjstd=βjσj\beta_j^{std}=\beta_j\sigma_j = effect per 1 SD.
Small-β\beta approximation for odds ratio?
eβ1+βe^\beta \approx 1+\beta, so β=0.05\beta=0.05 ≈ +5% odds.
Why can correlated features make coefficients unreliable?
Multicollinearity makes the fit unable to attribute effect uniquely, so coefficients get large variance and can flip sign.
Does a significant coefficient prove causation?
No — it shows association; causal claims need a causal design and control of confounders.

Concept Map

defined as

requires

applies in

applies in

coefficient means

coefficient means

exponentiate

includes

y when all x=0

depends on

affected by

Model coefficient beta_j

Partial derivative

Ceteris paribus

Linear regression

Logistic regression

Change in y units

Change in log-odds

Odds ratio e^beta_j

Intercept beta_0

Trustworthiness

Scaling and correlation

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Coefficient ka matlab simple hai: agar tum ek feature ko 1 unit badhao aur baaki sab constant rakho, to prediction kitna badlega — wahi number coefficient hai. Linear regression mein yeh seedha "add" hota hai: sqft ka coefficient 300 hai matlab har extra square foot se price mein $300 add ho jaate hain, bedrooms same rakhte hue. Woh "baaki sab same rakhte hue" wali line bahut important hai, warna interpretation galat ho jaati hai.

Logistic regression mein twist hai. Yahan coefficient probability pe seedha kaam nahi karta — woh log-odds pe kaam karta hai. Isliye interpret karne ke liye tumhe eβe^{\beta} nikaalna padta hai, aur woh batata hai ki odds kitne guna ho jaate hain. Jaise β=0.8\beta=0.8 ho to e0.82.23e^{0.8}\approx 2.23, matlab odds 2.23 times ho gaye. Mantra yaad rakho: "Linear adds, Logistic multiplies."

Ek badi galti: yeh sochna ki bada coefficient matlab zyada important feature. Nahi! Coefficient feature ke scale pe depend karta hai. Income dollars mein hai (bade numbers) to uska coefficient chhota dikhega, age years mein hai to bada. Fair comparison ke liye pehle features ko standardize karo (mean minus, SD se divide), tabhi magnitudes compare karo.

Aur dhyaan rakho: correlated features (multicollinearity) hone par coefficients unstable ho jaate hain, sign tak flip kar sakte hain, kyunki model decide nahi kar paata kis feature ko credit de. Aur haan — significant coefficient sirf association dikhata hai, causation nahi. Yeh cheezein interview aur real projects dono mein pucchi jaati hain.

Go deeper — visual, from zero

Test yourself — Linear & Logistic Regression

Connections