ML Study Hub
← Back to Study Hub
Module 01 · Regression
← Hub
Intuition OLS Proof Normal Eq Gradient Descent Ridge/Lasso Traps Past Papers OLS Tool Quiz Checklist
Module 01 · Analytical Foundations & Proofs

Linear Regression & Optimization

The mathematical backbone of supervised machine learning. Covers Ordinary Least Squares (OLS) closed-form derivations, matrix formulations, gradient descent optimization, regularization geometry, and regression evaluation metrics.

Jan 2025 (Q1 20M) OLS Derivations Normal Equation Ridge vs Lasso Bias-Variance

01. Intuition & Concept Contrast

Linear regression fits an optimal hyperplanar trend line through empirical observations by minimizing the sum of squared vertical discrepancies between predicted points and ground-truth responses.

Model Paradigm

Simple vs Multiple Linear Regression

Simple Linear Regression (SLR): Single scalar feature $X \in \mathbb{R}$ predicting scalar response $Y \in \mathbb{R}$ via 2 parameters (slope $\beta_1$ and intercept $\beta_0$).

Multiple Linear Regression (MLR): Vector of $d$ features $\mathbf{x} \in \mathbb{R}^d$ predicting $Y$ via hyperplane defined by $d+1$ parameters ($\mathbf{w} \in \mathbb{R}^d$ and bias $b$).

Optimization Paradigm

Closed-Form (OLS) vs Iterative (Gradient Descent)

Ordinary Least Squares (OLS): Direct exact analytical solution using calculus ($\hat{\boldsymbol{\beta}} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}$). Perfect for $n \le 10^5, d \le 10^3$; suffers from $O(d^3)$ matrix inversion complexity.

Gradient Descent (GD): Iterative step-by-step optimization along negative error gradients ($\mathbf{w} \leftarrow \mathbf{w} - \alpha \nabla_{\mathbf{w}}\mathcal{L}$). Scales to billions of samples and high dimensions.

Complexity Trade-off

Underfitting vs Overfitting in Academics

Underfitting (High Bias, Low Variance): A flat or overly rigid line that fails to capture the learning curve (e.g., predicting that study hours have zero effect on test scores). High training and test errors.

Overfitting (Low Bias, High Variance): A high-degree polynomial that memorizes noisy individual test quirks. Zero training error, but catastrophic test failure on unseen students.

Regularization Geometry

Ridge ($L_2$) vs Lasso ($L_1$)

Ridge Regression ($L_2$ Penalty $\lambda \|\mathbf{w}\|_2^2$): Smooth circular constraint contour. Shrinks coefficients continuously toward zero but never forces exact zeros. Retains all features.

Lasso Regression ($L_1$ Penalty $\lambda \|\mathbf{w}\|_1$): Sharp diamond constraint contour with corners on coordinate axes. Forces non-informative feature weights to exactly $0$, performing automated feature selection.

02. Mathematical Proofs (The OLS Derivation)

Guaranteed University Exam Proof (10 Marks). Derivation of the optimal slope ($\hat{\beta}_1$) and intercept ($\hat{\beta}_0$) via Ordinary Least Squares.

The Closed-Form OLS Equations
$$\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2} = \frac{\operatorname{Cov}(X, Y)}{\operatorname{Var}(X)}, \qquad \hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}$$ Where $\bar{X} = \frac{1}{n}\sum X_i$ and $\bar{Y} = \frac{1}{n}\sum Y_i$.
Step-by-Step Derivation Protocol for Exam Hall:

Step 1: Setup Objective Function (Residual Sum of Squares)

Given $n$ paired observations $\{(X_i, Y_i)\}_{i=1}^n$, the linear model is $Y_i = \beta_0 + \beta_1 X_i + \epsilon_i$. The predicted value is $\hat{Y}_i = \beta_0 + \beta_1 X_i$.

The OLS criterion minimizes the Residual Sum of Squares (RSS), denoted as $S(\beta_0, \beta_1)$:

$$\begin{aligned} S(\beta_0, \beta_1) &= \sum_{i=1}^n (Y_i - \hat{Y}_i)^2 \\[4pt] &= \sum_{i=1}^n \left(Y_i - \beta_0 - \beta_1 X_i\right)^2 \end{aligned}$$

Step 2: Partial Derivative with respect to Intercept ($\beta_0$)

Apply the chain rule and set the partial derivative equal to zero to find the stationary point:

$$\begin{aligned} \frac{\partial S}{\partial \beta_0} &= -2 \sum_{i=1}^n \left(Y_i - \beta_0 - \beta_1 X_i\right) = 0 \\[6pt] \sum_{i=1}^n Y_i - \sum_{i=1}^n \beta_0 - \beta_1 \sum_{i=1}^n X_i &= 0 \\[6pt] \sum_{i=1}^n Y_i - n\beta_0 - \beta_1 \sum_{i=1}^n X_i &= 0 \end{aligned}$$

Divide the entire equation by $n$:

$$\begin{aligned} \frac{1}{n}\sum_{i=1}^n Y_i - \beta_0 - \beta_1 \left(\frac{1}{n}\sum_{i=1}^n X_i\right) &= 0 \\[6pt] \bar{Y} - \beta_0 - \beta_1 \bar{X} &= 0 \\[6pt] \mathbf{\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}} &\quad \text{--- (Equation 1)} \end{aligned}$$

Step 3: Partial Derivative with respect to Slope ($\beta_1$)

Differentiate $S(\beta_0, \beta_1)$ with respect to $\beta_1$ and set to zero:

$$\begin{aligned} \frac{\partial S}{\partial \beta_1} &= -2 \sum_{i=1}^n X_i \left(Y_i - \beta_0 - \beta_1 X_i\right) = 0 \\[6pt] \sum_{i=1}^n X_i Y_i - \beta_0 \sum_{i=1}^n X_i - \beta_1 \sum_{i=1}^n X_i^2 &= 0 \quad \text{--- (Equation 2)} \end{aligned}$$

Step 4: Substitute Equation 1 into Equation 2

Substitute $\beta_0 = \bar{Y} - \beta_1 \bar{X}$ into Equation 2:

$$\begin{aligned} \sum_{i=1}^n X_i Y_i - (\bar{Y} - \beta_1 \bar{X})\sum_{i=1}^n X_i - \beta_1 \sum_{i=1}^n X_i^2 &= 0 \\[6pt] \sum_{i=1}^n X_i Y_i - \bar{Y}\sum_{i=1}^n X_i + \beta_1 \bar{X}\sum_{i=1}^n X_i - \beta_1 \sum_{i=1}^n X_i^2 &= 0 \end{aligned}$$

Notice that $\sum X_i = n\bar{X}$ and $\bar{Y}\sum X_i = \bar{Y}(n\bar{X}) = n\bar{X}\bar{Y}$:

$$\begin{aligned} \sum_{i=1}^n X_i Y_i - n\bar{X}\bar{Y} - \beta_1 \left(\sum_{i=1}^n X_i^2 - n\bar{X}^2\right) &= 0 \\[6pt] \beta_1 \left(\sum_{i=1}^n X_i^2 - n\bar{X}^2\right) &= \sum_{i=1}^n X_i Y_i - n\bar{X}\bar{Y} \end{aligned}$$

Using the algebraic centering identities $\sum (X_i - \bar{X})^2 = \sum X_i^2 - n\bar{X}^2$ and $\sum (X_i - \bar{X})(Y_i - \bar{Y}) = \sum X_i Y_i - n\bar{X}\bar{Y}$:

$$\mathbf{\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2}} \quad \text{Q.E.D.}$$

03. Matrix Normal Equation (Multiple Linear Regression)

When modeling multiple features $\mathbf{y} = \mathbf{X}\boldsymbol{\beta} + \boldsymbol{\epsilon}$, calculus is executed using compact matrix vectorization.

The Normal Equation
$$\hat{\boldsymbol{\beta}} = \left(\mathbf{X}^T \mathbf{X}\right)^{-1} \mathbf{X}^T \mathbf{y}$$ Where $\mathbf{X} \in \mathbb{R}^{n \times (d+1)}$, $\mathbf{y} \in \mathbb{R}^{n \times 1}$, and $\boldsymbol{\beta} \in \mathbb{R}^{(d+1) \times 1}$.

Matrix Derivation Protocol:

$$\begin{aligned} \mathbf{e} &= \mathbf{y} - \mathbf{X}\boldsymbol{\beta} \\[4pt] \operatorname{RSS}(\boldsymbol{\beta}) &= \mathbf{e}^T \mathbf{e} = (\mathbf{y} - \mathbf{X}\boldsymbol{\beta})^T (\mathbf{y} - \mathbf{X}\boldsymbol{\beta}) \\[4pt] &= \mathbf{y}^T \mathbf{y} - \mathbf{y}^T \mathbf{X}\boldsymbol{\beta} - \boldsymbol{\beta}^T \mathbf{X}^T \mathbf{y} + \boldsymbol{\beta}^T \mathbf{X}^T \mathbf{X}\boldsymbol{\beta} \\[4pt] &= \mathbf{y}^T \mathbf{y} - 2\boldsymbol{\beta}^T \mathbf{X}^T \mathbf{y} + \boldsymbol{\beta}^T \mathbf{X}^T \mathbf{X}\boldsymbol{\beta} \end{aligned}$$

Take the matrix derivative with respect to parameter vector $\boldsymbol{\beta}$:

$$\begin{aligned} \nabla_{\boldsymbol{\beta}} \operatorname{RSS}(\boldsymbol{\beta}) &= -2\mathbf{X}^T \mathbf{y} + 2\mathbf{X}^T \mathbf{X}\boldsymbol{\beta} = \mathbf{0} \\[6pt] \mathbf{X}^T \mathbf{X}\boldsymbol{\beta} &= \mathbf{X}^T \mathbf{y} \\[6pt] \mathbf{\hat{\boldsymbol{\beta}}} &= \mathbf{\left(\mathbf{X}^T \mathbf{X}\right)^{-1} \mathbf{X}^T \mathbf{y}} \end{aligned}$$
Exam Trap: When is $(\mathbf{X}^T\mathbf{X})$ Non-Invertible?
1. Multicollinearity: Two or more features are perfectly linearly dependent, reducing the matrix rank below $d+1$.
2. High Dimensions ($p > n$): More features than observations guarantees rank $\le n < p$, producing a singular matrix.
Remedy: Add $L_2$ Ridge regularization: $(\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1}\mathbf{X}^T\mathbf{y}$, which is strictly positive-definite and always invertible.

04. Gradient Descent Optimization Variants

Gradient descent iteratively updates parameters along the negative gradient of the loss surface: $\boldsymbol{\theta} \leftarrow \boldsymbol{\theta} - \alpha \nabla_{\boldsymbol{\theta}} \mathcal{L}(\boldsymbol{\theta})$.

Dimension Batch Gradient Descent (BGD) Stochastic Gradient Descent (SGD) Mini-Batch Gradient Descent (MBGD)
Batch Size Full dataset ($m = n$) Single sample ($m = 1$) Subset ($m \in [32, 256]$)
Trajectory Monotonic, smooth straight path Highly noisy, zig-zag stochastic path Balanced, steady path
Memory Cost High: requires entire data in RAM Minimal: processes one row at a time Optimal: fits modern GPU caches
Local Minima Can get trapped in saddle points High noise helps jump out of local minima Smooth vectorization with escape capability

Role of the Learning Rate ($\alpha$)

$\alpha$ Too Small: Tiny incremental steps; convergence requires millions of epochs, risking process timeout.

$\alpha$ Too Large: Parameter updates overshoot the cost function valley, causing the loss to oscillate or diverge to $+\infty$.

05. Regularization & Evaluation Metrics

L2 Penalty

Ridge Regression

$$\min_{\mathbf{w}} \frac{1}{2n}\sum_{i=1}^n (y_i - \mathbf{w}^T\mathbf{x}_i)^2 + \lambda \|\mathbf{w}\|_2^2$$

Penalizes large weights smoothly by adding $\lambda \sum w_j^2$. The circular contour shrinks all parameters proportionally toward zero, preventing extreme oscillations caused by collinear features.

L1 Penalty

Lasso Regression

$$\min_{\mathbf{w}} \frac{1}{2n}\sum_{i=1}^n (y_i - \mathbf{w}^T\mathbf{x}_i)^2 + \lambda \|\mathbf{w}\|_1$$

Penalizes the absolute sum of weights $\lambda \sum |w_j|$. The non-differentiable sharp corners of the $L_1$ diamond hit the cost function along coordinate axes, driving irrelevant feature weights to exact zero.

Regression Evaluation Metrics Reference

Metric Mathematical Formula Interpretation & Examiner Utility
Mean Squared Error (MSE) $\frac{1}{n}\sum_{i=1}^n (Y_i - \hat{Y}_i)^2$ Penalizes large outlier errors quadratically. Units are squared (e.g., $\text{marks}^2$).
Root Mean Squared Error (RMSE) $\sqrt{\frac{1}{n}\sum_{i=1}^n (Y_i - \hat{Y}_i)^2}$ Restores error to natural target units ($\text{marks}$). Directly interpretable.
Mean Absolute Error (MAE) $\frac{1}{n}\sum_{i=1}^n |Y_i - \hat{Y}_i|$ Linear penalty; robust to extreme outliers that would distort MSE.
Coefficient of Determination ($R^2$) $1 - \frac{\text{SS}_{\text{res}}}{\text{SS}_{\text{tot}}} = 1 - \frac{\sum(Y_i - \hat{Y}_i)^2}{\sum(Y_i - \bar{Y})^2}$ Proportion of total target variance explained by the model ($R^2 \in [0, 1]$).
Adjusted $R^2$ $1 - \left[\frac{(1 - R^2)(n - 1)}{n - p - 1}\right]$ Penalizes adding useless features ($p$). Increases only if new feature improves model beyond chance.

06. Notation Decoding Matrix

Quick reference table mapping academic mathematical symbols to practical implementations.

Symbol Formal Name Plain-English Meaning Applied Exam Example
$X_i, Y_i$ Feature & Target Pair Input variable and output observation $X = \text{Study Hours}, Y = \text{Exam Score}$
$\hat{\beta}_1$ Slope Parameter Expected change in $Y$ per unit increase in $X$ $\hat{\beta}_1 = 5.0 \implies +5\text{ marks per additional hour}$
$\hat{\beta}_0$ Intercept Parameter Expected value of $Y$ when $X = 0$ $\hat{\beta}_0 = 40.0 \implies \text{Baseline score with } 0\text{ hours}$
$e_i = Y_i - \hat{Y}_i$ Residual / Error Vertical distance from data point to line Actual: $70$, Predicted: $65 \implies e_i = +5$
$\text{SS}_{\text{res}}$ Residual Sum of Squares Unexplained variance remaining in model $\sum (Y_i - \hat{Y}_i)^2$ (Minimized by OLS)
$\text{SS}_{\text{tot}}$ Total Sum of Squares Total variance in dependent variable around mean $\sum (Y_i - \bar{Y})^2$
$\alpha$ Learning Rate Step size scale factor in gradient descent $\alpha = 0.01$ step along negative gradient
$\lambda$ Regularization Coefficient Penalty weight balancing fit vs complexity $\lambda = 0 \implies \text{OLS}; \lambda \to \infty \implies \mathbf{w} \to \mathbf{0}$

07. Repeatable Step-by-Step Solving Protocol

Follow this numbered protocol to compute regression models without arithmetic errors under exam pressure:

Step 1: Compute Sample Means $$\bar{X} = \frac{1}{n}\sum_{i=1}^n X_i, \qquad \bar{Y} = \frac{1}{n}\sum_{i=1}^n Y_i$$
Step 2: Construct Deviation Columns

Compute deviations for every point: $(X_i - \bar{X})$, $(Y_i - \bar{Y})$, squared deviations $(X_i - \bar{X})^2$, and cross-products $(X_i - \bar{X})(Y_i - \bar{Y})$.

Step 3: Calculate Slope ($\hat{\beta}_1$) $$\hat{\beta}_1 = \frac{\sum (X_i - \bar{X})(Y_i - \bar{Y})}{\sum (X_i - \bar{X})^2}$$
Step 4: Calculate Intercept ($\hat{\beta}_0$) $$\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}$$
Step 5: Write the Prediction Equation $$\hat{Y} = \hat{\beta}_0 + \hat{\beta}_1 X$$
Step 6: Compute Residuals & $R^2$ Variance Explained $$\text{SS}_{\text{res}} = \sum (Y_i - \hat{Y}_i)^2, \quad \text{SS}_{\text{tot}} = \sum (Y_i - \bar{Y})^2, \quad R^2 = 1 - \frac{\text{SS}_{\text{res}}}{\text{SS}_{\text{tot}}}$$

08. 6 Deadly Exam Traps & Common Student Mistakes

Examiners frequently deduct marks for these 6 subtle missteps:

Trap 01: Denominator Confusion

Dividing by $n$ or $\operatorname{Var}(Y)$ in Slope

Students write $\hat{\beta}_1 = \frac{\sum (X-\bar{X})(Y-\bar{Y})}{\sum (Y-\bar{Y})^2}$. The denominator MUST be the variance of the independent variable $X$ ($\sum (X-\bar{X})^2$). Dividing by $Y$ flips the regression.

Trap 02: Forgetting Intercept Column

Missing Column of Ones in Matrix $\mathbf{X}$

In matrix formulation, $\mathbf{X}$ must include an initial column of $1$'s: $\mathbf{X} = [\mathbf{1} \,\|\, \mathbf{x}_1 \,\|\, \dots]$. Omitting this forces the regression line through the origin ($b = 0$), destroying prediction accuracy.

Trap 03: Unit Discrepancy

Reporting MSE in Units of Target

If $Y$ is in dollars or exam marks, $\text{MSE}$ is in $\text{dollars}^2$ or $\text{marks}^2$. Always state that $\text{RMSE}$ is required for direct unit interpretation.

Trap 04: The Monotonic $R^2$ Illusion

Assuming Higher $R^2$ Always Means Better Model

Adding junk features into multiple linear regression will never decrease $R^2$. It will either stay the same or artificially increase. Examiners require explaining Adjusted $R^2$ to penalize parameter bloat.

Trap 05: Lasso on Collinear Features

Believing Lasso Selects All Correlated Features

When two features are highly collinear ($r > 0.95$), Lasso arbitrarily selects only one feature and sets the other to zero. Ridge retains both with shrunken weights.

Trap 06: Swapping Bias and Variance

Confusing Underfitting with High Variance

Underfitting = High Bias (inflexible model, ignores data). Overfitting = High Variance (hyper-flexible model, memorizes sample noise).

09. Complete University Question Bank (All Past PYQs Solved)

Every question from available semester exams, continuous tests, and the question bank solved step-by-step.

Jan 2025 · Question 1 Simple Linear Regression Derivation, Overfitting & Metrics (20 Marks)
Question Statement:
i) Consider a dataset where independent variable $X$ represents study hours, and dependent variable $Y$ represents exam scores: Explain the process of deriving the simple linear regression equation. Describe mathematical steps to calculate slope and intercept. Interpret the line in context. (10 Marks)
ii) Define overfitting and underfitting in student performance prediction and their impact on reliability. (5 Marks)
iii) Identify and explain commonly used evaluation metrics for regression models in student exam score prediction. (5 Marks)

Solution:

(i) Derivation and Interpretation (10 Marks)

1. Model Setup: Let $Y_i = \beta_0 + \beta_1 X_i + \epsilon_i$, where predicted score is $\hat{Y}_i = \hat{\beta}_0 + \hat{\beta}_1 X_i$.

2. Objective: Minimize Residual Sum of Squares $S(\beta_0, \beta_1) = \sum_{i=1}^n (Y_i - \beta_0 - \beta_1 X_i)^2$.

3. Partial Derivative for $\beta_0$:

$$\frac{\partial S}{\partial \beta_0} = -2\sum (Y_i - \beta_0 - \beta_1 X_i) = 0 \implies \mathbf{\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}}$$

4. Partial Derivative for $\beta_1$:

$$\frac{\partial S}{\partial \beta_1} = -2\sum X_i(Y_i - \beta_0 - \beta_1 X_i) = 0$$

Substituting $\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}$ yields:

$$\sum X_i Y_i - \bar{Y}\sum X_i - \hat{\beta}_1\left(\sum X_i^2 - \bar{X}\sum X_i\right) = 0$$ $$\mathbf{\hat{\beta}_1 = \frac{\sum_{i=1}^n (X_i - \bar{X})(Y_i - \bar{Y})}{\sum_{i=1}^n (X_i - \bar{X})^2}}$$

5. Interpretation in Context:

  • Slope ($\hat{\beta}_1$): The marginal score increase per additional hour studied. If $\hat{\beta}_1 = 4.5$, every additional hour increases expected exam score by $4.5$ marks.
  • Intercept ($\hat{\beta}_0$): Baseline score expected for a student studying zero hours ($X = 0$). If $\hat{\beta}_0 = 35.0$, a student with $0$ hours is predicted to score $35.0$ marks.
(ii) Overfitting vs Underfitting (5 Marks)
  • Underfitting (High Bias): The model assumes a constant horizontal line or inadequate structure. It fails to capture that more study hours improve performance. Impact: Systematically underestimates hardworking students and overestimates non-studying students.
  • Overfitting (High Variance): The model uses an 8th-degree polynomial to pass through every single training student's data point, memorizing quirks like a student who studied 10 hours but had the flu and scored 20. Impact: Unreliable generalization; predictions fluctuate wildly on unseen students.
(iii) Evaluation Metrics for Exam Score Prediction (5 Marks)
  1. MSE: Penalizes large prediction errors severely.
  2. RMSE: Expresses error in original exam marks (e.g., $\text{RMSE} = 4.2 \text{ marks}$ error on average).
  3. MAE: Robust average error without quadratic exaggeration.
  4. $R^2$ Score: Measures what percentage of score variance is explained by study hours (e.g., $R^2 = 0.82 \implies 82\%$ explained).
  5. Adjusted $R^2$ Score: Validates whether adding extra features (e.g., student attendance, sleep hours) provides genuine explanatory power.
Part B QB · Set 1 Multiple Linear Regression Matrix Normal Equation Derivation (16 Marks)
Question Statement:
Derive the Normal Equation for Multiple Linear Regression using matrix calculus: $\hat{\boldsymbol{\beta}} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}$. State the dimensions of all matrices and discuss conditions where $\mathbf{X}^T\mathbf{X}$ cannot be inverted. (16 Marks)

Solution:

1. Matrix Dimensions:

  • $\mathbf{y} \in \mathbb{R}^{n \times 1}$: Vector of observed responses.
  • $\mathbf{X} \in \mathbb{R}^{n \times (d+1)}$: Design matrix with first column all ones ($x_{i0} = 1$).
  • $\boldsymbol{\beta} \in \mathbb{R}^{(d+1) \times 1}$: Parameter vector $[\beta_0, \beta_1, \dots, \beta_d]^T$.
  • $\mathbf{e} \in \mathbb{R}^{n \times 1}$: Residual error vector $\mathbf{e} = \mathbf{y} - \mathbf{X}\boldsymbol{\beta}$.

2. Matrix RSS Expansion:

$$S(\boldsymbol{\beta}) = \mathbf{e}^T\mathbf{e} = (\mathbf{y} - \mathbf{X}\boldsymbol{\beta})^T(\mathbf{y} - \mathbf{X}\boldsymbol{\beta}) = \mathbf{y}^T\mathbf{y} - 2\boldsymbol{\beta}^T\mathbf{X}^T\mathbf{y} + \boldsymbol{\beta}^T\mathbf{X}^T\mathbf{X}\boldsymbol{\beta}$$

3. Matrix Differentiation:

$$\frac{\partial S}{\partial \boldsymbol{\beta}} = -2\mathbf{X}^T\mathbf{y} + 2\mathbf{X}^T\mathbf{X}\boldsymbol{\beta} = \mathbf{0}$$ $$\mathbf{X}^T\mathbf{X}\boldsymbol{\beta} = \mathbf{X}^T\mathbf{y} \implies \mathbf{\hat{\boldsymbol{\beta}} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}}$$

4. Singularity Conditions:

  • Collinearity: $\operatorname{Rank}(\mathbf{X}) < d+1$, meaning one feature is a linear combination of others.
  • $p > n$: More features than observations guarantees that $\operatorname{det}(\mathbf{X}^T\mathbf{X}) = 0$.
  • Fix: Ridge regularization $(\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1}\mathbf{X}^T\mathbf{y}$.
Nov 2025 · Question 3 Structural Failure of Linear Regression on Complex Non-Linear Text Data (10 Marks)
Question Statement:
A marketing team leader suggests using simple linear regression to predict customer satisfaction from structured data and unstructured text feedback. Justify why linear regression fails in this scenario. (10 Marks)

Solution:

  1. Rigid Hyperplanar Space: Linear regression assumes constant marginal rate of change $\frac{\partial y}{\partial x_j} = \beta_j$. Satisfaction exhibits non-linear saturation, threshold steps, and dimishing returns that linear planes cannot represent.
  2. High Dimensionality & Sparsity ($p \gg n$): Vectorizing unstructured text produces vocabulary spaces with thousands of terms ($d > 5000$). When $d > n$, $\mathbf{X}^T\mathbf{X}$ is rank-deficient and singular, causing OLS to collapse.
  3. Lack of Cross-Modal Interaction: Linear models cannot capture feature interactions (e.g., High Price is acceptable IF Quality is High, but disastrous IF Quality is Low) without manual polynomial expansion.

10. Interactive Offline OLS Regression Solver

Test your calculations. Enter paired $(X, Y)$ observations separated by commas to instantly compute means, slope, intercept, $R^2$, and evaluate predictions.

Click the button above to calculate regression parameters.

11. Active Recall Self-Test Quiz

Check your mastery before entering the exam hall. Instant feedback provided for each question.

Answer the questions below to evaluate progress (0/4 answered).
1. In simple linear regression, Ordinary Least Squares minimizes which quantity?
Correct: (b) OLS minimizes $\sum (Y_i - \hat{Y}_i)^2$, which represents vertical squared errors.
2. If $n = 5$, $\bar{X} = 6.0$, $\bar{Y} = 70.0$, and the calculated slope is $\hat{\beta}_1 = 5.0$, what is the intercept $\hat{\beta}_0$?
Correct: (c) $\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X} = 70.0 - (5.0 \times 6.0) = 70 - 30 = \mathbf{40.0}$.
3. Why does Lasso ($L_1$) regression produce sparse models (exact zero weights) while Ridge ($L_2$) does not?
Correct: (a) The diamond geometry of the $L_1$ ball intersects the elliptical loss contours at coordinate axes, setting irrelevant weights to exactly zero.
4. What is the main advantage of Adjusted $R^2$ over standard $R^2$ in multiple regression?
Correct: (c) Adjusted $R^2 = 1 - \frac{(1-R^2)(n-1)}{n-p-1}$, which decreases if adding feature $p$ fails to compensate for the lost degree of freedom.

12. Exam Hall Answer Sheet Presentation Checklist

Follow this structured template on your physical exam answer booklet to secure maximum marks:

1. Define Model & Variables Explicitly

Write: "Let $X$ denote the independent variable (Study Hours) and $Y$ denote the dependent response (Exam Score). Model: $Y = \beta_0 + \beta_1 X + \epsilon$."

2. State the OLS Minimization Criterion

Write: "Minimize $S(\beta_0, \beta_1) = \sum_{i=1}^n (Y_i - \beta_0 - \beta_1 X_i)^2$."

3. Show Both First-Order Conditions

Write the partial derivative steps $\frac{\partial S}{\partial \beta_0} = 0$ and $\frac{\partial S}{\partial \beta_1} = 0$ with equation numbers.

4. Box the Final Governing Formulas

Draw a clean box around $\hat{\beta}_0 = \bar{Y} - \hat{\beta}_1 \bar{X}$ and $\hat{\beta}_1 = \frac{\sum (X-\bar{X})(Y-\bar{Y})}{\sum (X-\bar{X})^2}$.

5. Interpret Both Slope and Intercept with Concrete Units

Never leave raw numbers alone. Always write: "Slope $\hat{\beta}_1 = 5.0$ indicates an expected gain of $5$ marks per hour; intercept $\hat{\beta}_0 = 40.0$ indicates baseline score for zero hours."

6. For Bias-Variance Questions, State the Decomposition

Write: $\text{Error} = \text{Bias}^2 + \text{Variance} + \sigma_\epsilon^2$. Mention that underfitting = high bias, overfitting = high variance.