The linear model and least-squares estimation — closed-form slope and intercept for simple regression, the matrix form and normal equations for multiple regression, geometric interpretation as projection, properties of residuals, R² and its link to correlation, assumptions and diagnostics, interpreting coefficients, categorical predictors and interactions, multicollinearity, and fitting by gradient descent.
"Linear" refers to linearity in the parameters: y=β0+β1x+β2x2 (polynomial regression) and y=β0+β1logx are still linear regressions.
Simple linear regression
Minimise SSE(β0,β1)=∑i(yi−β0−β1xi)2. Setting both partial derivatives to zero:
β^1=SxxSxy=∑(xi−xˉ)2∑(xi−xˉ)(yi−yˉ)=rsxsy,β^0=yˉ−β^1xˉ.Least squares fits the line minimising squared vertical residuals.
Properties of the OLS fit (with an intercept):
residuals sum to zero, ∑ei=0, and are orthogonal to x: ∑xiei=0;
the line passes through (xˉ,yˉ);
SStot=SSreg+SSres, and R2=SSreg/SStot=r2;
the regression of x on y is a different line (slope product =r2).
Multiple linear regression
Stack the data into the design matrix X (n×(p+1), a column of ones for the intercept):
β^=argmin∥y−Xβ∥2=(X⊤X)−1X⊤y.
Geometry: y^=Xβ^=Hy is the orthogonal projection of y onto the column space of X, with hat matrix H=X(X⊤X)−1X⊤; the residual vector is orthogonal to every column (see projections).
Interpretation: β^j is the expected change in y for a one-unit increase in xjholding the other features fixed. Coefficients from a multiple regression can differ (even in sign) from simple-regression slopes when features are correlated.
Categorical predictors and interactions
A categorical feature with k levels becomes k−1dummy (one-hot) variables; using all k with an intercept makes X rank-deficient (the dummy-variable trap).
An interaction term x1x2 lets the effect of x1 depend on x2.
Assumptions and diagnostics
For inference (standard errors, t-tests, confidence intervals) the classical assumptions are: linearity, independent errors, homoscedasticity (constant error variance), normally distributed errors, and no perfect multicollinearity. Under the first four (Gauss–Markov without normality), OLS is the best linear unbiased estimator (BLUE); with normal errors it is also the maximum likelihood estimator.
Each coefficient's significance is tested with t=β^j/SE(β^j) on n−p−1 degrees of freedom; the error variance is estimated by σ^2=SSres/(n−p−1).
Fitting by gradient descent
When p is large, solving the normal equations (O(np2+p3)) is replaced by gradient descent on the MSE:
∇βn1∥Xβ−y∥2=n2X⊤(Xβ−y),β←β−ηn2X⊤(Xβ−y).
The loss is convex (a quadratic bowl), so gradient descent converges to the global minimum for a small enough η; feature scaling speeds it up dramatically. Stochastic or mini-batch versions use a subset of rows per step.
Quick revision
Practice questions
GATE-style questions: 5 one-mark and 5 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
Q1NAT2 marks
For the data (x,y): (1,2),(2,4),(3,5),(4,4),(5,5), the least-squares slope β^1 of y=β0+β1x is ______.
Q2NAT1 mark
For the same data (1,2),(2,4),(3,5),(4,4),(5,5), the least-squares intercept β^0 is ______.
Q3NAT1 mark
Using the fitted line y^=2.2+0.6x, the predicted value at x=6 is ______.
Q4MCQ1 mark
Ordinary least squares chooses the regression coefficients that minimise
Q5NAT2 marks
For the data (1,2),(2,4),(3,5),(4,4),(5,5) with fitted line y^=2.2+0.6x, the coefficient of determination R2 is ______.
Q6MSQ2 marks
For an OLS fit of y=β0+β1x (with intercept), which statements always hold?
One or more options are correct.
Q7MCQ2 marks
In matrix form y=Xβ+ε with X of full column rank, the least-squares estimate is
Q8NAT1 mark
A fitted multiple regression model is y^=3+2x1−0.5x2. Its prediction for x1=4, x2=6 is ______.
Q9MCQ1 mark
Two features in a multiple regression are almost perfectly correlated. The most likely consequence is
Q10NAT2 marks
The model y^=wx (no intercept) is fitted to the points (1,2) and (2,4) by gradient descent on J(w)=n1∑i(wxi−yi)2, starting from w=0 with learning rate 0.1. The value of w after one update is ______.