Statistics · medium

What are the assumptions of linear regression, and how do you check them?

Asked in Data Scientist interviews, in the Statistics round.

Short answer

Linear relationship, independent errors, constant error variance, normal errors for inference, and no severe multicollinearity. Check with residual plots, a Durbin Watson or autocorrelation plot, a scale location plot, a Q-Q plot, and VIF.

How to answer it

List them, then say how you would look for each. The check is what interviewers are listening for.

import statsmodels.api as sm
model = sm.OLS(y, sm.add_constant(X)).fit()
resid, fitted = model.resid, model.fittedvalues   # plot these against each other

The distinction to draw: a violated assumption rarely breaks the predictions much, it breaks the standard errors and therefore the p-values. If the question is "does this feature matter", the assumptions matter. If the question is "predict next month", they matter less.

Related questions

Practice this for real