MoonSay /Tutorials/Machine Learning Interview #14
Contents
  1. 01Introduction
  2. 02Least squares
  3. 03Unbiasedness
  4. 04Least variance
  5. 05Distribution and confidence
  6. 06Interview follow-ups
  7. 07Common misconceptions
  8. 08Interview questions and model answers
  9. 09Summary
  10. References

06Interview follow-ups

6.1Why squared residuals?

Three reasons. First, with normal errors, least squares is maximum likelihood (Episode 5). The log-likelihood of the model (1) with \varepsilon_i\sim\mathcal N(0,\sigma^2) is

\log L(\beta,\sigma^2)=\sum_{i=1}^{n}\log\Bigl[\frac{1}{\sqrt{2\pi\sigma^2}}\exp\Bigl(-\frac{(y_i-x_i^\top\beta)^2}{2\sigma^2}\Bigr)\Bigr]=-\frac{n}{2}\log(2\pi\sigma^2)-\frac{1}{2\sigma^2}\,\mathrm{RSS}(\beta), \tag{18}

so maximizing the likelihood over \beta is the same as minimizing RSS (Murphy, 2022, eq. 11.4–11.5). Second, squares give the closed form (5). Third, by Gauss–Markov, least squares is BLUE even without normality. The price is sensitivity to outliers: a residual twice as large counts four times as much; the absolute or Huber loss (Episode 7) is more robust.

6.2Is multicollinearity a violation?

Perfect collinearity is: if the columns of X are not linearly independent (one input variable is an exact linear combination of the others), X does not have full column rank, X^\top X cannot be inverted, and (5) has infinitely many solutions. The classic example is the dummy-variable trap, one indicator for every category plus an intercept. Strong but imperfect collinearity breaks none of Assumptions 1–5: the estimates stay unbiased and least squares stays BLUE. But it inflates their variance. For input j,

\Var(\hat\beta_j\mid X)=\frac{\sigma^2}{S_{jj}}\cdot\frac{1}{1-R_j^2},\qquad \mathrm{VIF}_j=\frac{1}{1-R_j^2}, \tag{19}

where S_{jj}=\sum_i(x_{ij}-\bar x_j)^2 and R_j^2 is the R^2 of regressing x_j on all the other inputs. The first factor is the one-input variance (11); the second, the variance inflation factor, says how much the other inputs inflate it. When x_j is almost a combination of the others, R_j^2 is close to 1 and the variance explodes: the data cannot tell the two inputs apart, so any split of their joint effect fits about equally well. A common rule of thumb flags a VIF above 5 or 10 (James et al., 2021, §3.3.3).

Multicollinearity in the data of Efron et al. (2004). (a) Two of the blood serum measurements, total cholesterol and LDL cholesterol. (b) Variance inflation factors (19) of the ten inputs in the full model; dotted and dashed lines: the rule-of-thumb levels 5 and 10. Computed for this tutorial, with the same data as the companion video.
Figure 7. Multicollinearity in the data of Efron et al. (2004). (a) Two of the blood serum measurements, total cholesterol and LDL cholesterol. (b) Variance inflation factors (19) of the ten inputs in the full model; dotted and dashed lines: the rule-of-thumb levels 5 and 10. Computed for this tutorial, with the same data as the companion video.

Worked example 6 (Cholesterol, twice). Total cholesterol and LDL cholesterol correlate at 0.90 (Figure 7a). In the model with all ten inputs their variance inflation factors are 59 and 39, and their coefficients take opposite signs, -1.09 and +0.75, with large standard errors. Drop LDL, and the coefficient of total cholesterol becomes -0.31 with a standard error of 0.16, while the fit barely changes (R^2 from 0.518 to 0.516).

Multicollinearity is a problem for interpretation, not for prediction. For stable coefficients, drop or combine the redundant inputs, or use ridge regression, which adds \lambda I to X^\top X and stabilizes the inverse (Episode 4).

6.3How do you check the assumptions?

Mostly with pictures of the residuals, which is why Anscombe (1973) insisted on plotting the data: his four famous data sets have the same means, variances, correlation and fitted line, and completely different pictures. Table 1 collects the classic checks. Only Assumption 2 has no residual check, because least squares makes the residuals uncorrelated with every included input by construction.

assumptionif it failshow to checkwhat to do
1 linearitybiased fitcurve in residuals vs fittedadd x^2, transform
2 zero-mean errorsbiased slopesknowledge of the problemadd the variable
3 constant variancewrong standard errorsfunnel in residuals vs fittedrobust errors, weights
4 independent errorserrors too smallresiduals over timeclustered errors
5 normal errorssmall-n tests not exactQ–Q plot of residualslarge n, bootstrap
full rankinflated variancevariance inflation factorsdrop, combine, ridge
Table 1. The assumptions, what a violation does, how to see it and what to do (James et al., 2021, §3.3.3).