SAMPLE EXAM ANSWER: Simple Linear Regression, Model Evaluation, and Churn Duality
Question: (i) A company wants to estimate an employee’s salary based on the number of years of experience. Using a suitable sample dataset, explain how a Simple Linear Regression model can be developed. Show the complete procedure for obtaining the regression line, slope, and intercept using the least-squares approach. [10 Marks] (ii) A machine learning model is designed to predict the selling price of a product. Explain how the accuracy of such a regression model can be assessed. Describe any suitable regression evaluation metrics and illustrate the calculation and significance of MAE and MSE. [5 Marks] (iii) Consider two machine learning models:
- Model A gives very high accuracy on the training data but considerably lower performance on test data.
- Model B performs poorly on both training and test data. Identify the problems exhibited by these two models and explain Overfitting and Underfitting, including their causes and possible remedies. [5 Marks]
Marks: 20 marks | Time: 30 minutes
✅ COMPLETE EXAM ANSWER
PART 1: SIMPLE LINEAR REGRESSION & LEAST-SQUARES DERIVATION (10 marks)
1.1 Definition & Theoretical Basis (2 marks)
Simple Linear Regression (SLR) is a supervised machine learning algorithm used to model the relationship between a single continuous independent variable (predictor/feature) and a continuous dependent variable (target).
Statistically, the relationship is formulated as:
Where:
- y = Dependent variable (target/output)
- x = Independent variable (feature/input)
- β₀ = Intercept (value of when )
- β₁ = Slope (expected change in per unit change in )
- ε = Random error term (, assuming zero mean and constant variance)
We fit a predicted regression line represented by:
Where is the predicted estimate of .
1.2 Least-Squares Parameter Derivation (3 marks)
The Least Squares Method estimates parameters and by minimizing the Sum of Squared Residuals (SSR):
To find the minimum, we set the partial derivatives with respect to and to zero:
Step A: Solving for Intercept ()
Since , we divide the entire equation by :
(This proves that the regression line must pass through the centroid ).
Step B: Solving for Slope ()
1.3 Worked Example with Sample Dataset (3 marks)
Problem: Predict Employee Monthly Salary (, in $1,000s) based on Years of Experience ()
| Employee () | Experience () | Monthly Salary () |
|---|---|---|
| 1 | 1 | 50 |
| 2 | 2 | 60 |
| 3 | 3 | 65 |
| 4 | 4 | 80 |
| 5 | 5 | 95 |
Step 1: Calculate Sample Means
Step 2: Calculate Numerator
| 1 | 50 | -2 | -20 | 40 |
| 2 | 60 | -1 | -10 | 10 |
| 3 | 65 | 0 | -5 | 0 |
| 4 | 80 | 1 | 10 | 10 |
| 5 | 95 | 2 | 25 | 50 |
| Sum | 110 |
Step 3: Calculate Denominator
| 1 | -2 | 4 |
| 2 | -1 | 1 |
| 3 | 0 | 0 |
| 4 | 1 | 1 |
| 5 | 2 | 4 |
| Sum | 10 |
Step 4: Calculate Slope ()
Interpretation: For each additional 1 year of experience, an employee's estimated monthly salary increases by $11,000 holding other things constant.
Step 5: Calculate Intercept ()
Interpretation: If an employee has 0 years of experience, their predicted starting base salary is $37,000 (baseline).
1.4 Final Regression Equation (2 marks)
Prediction Examples:
- For Years: ($64,500)
- For Years: ($103,000)
PART 2: REGRESSION ACCURACY & EVALUATION METRICS (5 marks)
For continuous targets, accuracy is assessed by measuring the distance between actual observed targets and predictions , representing the model's residuals ().
Metric 1: MAE - Mean Absolute Error (1.5 marks)
Mathematical Step-by-Step Calculation:
Errors derived from our regression line ():
| | Actual () | Predicted () | Error () | Absolute Error () | |:---:|:---:|:---:|:---:|:---:| | 1 | 50 | 48 | 2 | 2 | | 2 | 60 | 59 | 1 | 1 | | 3 | 65 | 70 | -5 | 5 | | 4 | 80 | 81 | -1 | 1 | | 5 | 95 | 92 | 3 | 3 | | Sum | | | 0 | 12 |
- Inference & Significance: On average, the model's predictions deviate from the actual salary by an absolute physical error of $2,400. MAE uses absolute values, treating all errors linearly. This makes MAE robust to outliers and highly intuitive for business communication.
Metric 2: MSE - Mean Squared Error (1.5 marks)
Mathematical Step-by-Step Calculation:
| Actual () | Predicted () | Error () | Squared Error () |
|---|---|---|---|
| 50 | 48 | 2 | 4 |
| 60 | 59 | 1 | 1 |
| 65 | 70 | -5 | 25 |
| 80 | 81 | -1 | 1 |
| 95 | 92 | 3 | 9 |
| Sum | 40 |
- Inference & Significance: MSE calculates the average of squared errors. By squaring the residuals, MSE is highly sensitive to outliers, penalizing larger errors exponentially. It is mathematically smooth and continuously differentiable, making it the default loss function for gradient-based optimization algorithms.
Metric 3: RMSE - Root Mean Squared Error (1 mark)
Calculation:
- Inference & Significance: RMSE takes the square root of MSE, shifting the units back to the original target scale. It represents the standard deviation of residuals, showing average error penalizing outliers.
Metric 4: R² - Coefficient of Determination (1 mark)
Calculation:
Given , and mean :
- Inference & Significance: The model explains 96.80% of the total variance in monthly salaries based on experience, indicating an exceptional, high-quality linear fit.
PART 3: THE BIAS-VARIANCE RISK PROFILE (5 marks)
This scenario illustrates the fundamental Bias-Variance Tradeoff in machine learning:
BIAS-VARIANCE RISK PROFILE:
- Model A ──> High training score, low test score ──> OVERFITTING (High Variance, Low Bias)
- Model B ──> Low training score, low test score ──> UNDERFITTING (High Bias, Low Variance)
3.1 Model A: Overfitting (High Variance, Low Bias) (2.5 marks)
- Problem Identification: Model A is exhibiting Overfitting.
- Description: The model learns both the underlying statistical relationships and the random noise/outliers present in the training set. It lacks generalization capacity, failing on unseen test data.
- Causes:
- Excessive Model Complexity: Having too many parameters (e.g., fitting a high-degree polynomial regression, or unconstrained deep decision trees).
- Insufficient Training Data: Small datasets that the model can easily "memorize" rather than learning generalized features.
- Possible Remedies:
- Regularization: Apply L1 (Lasso) or L2 (Ridge) penalties to constrain and shrink parameter weights.
- Dimensionality Reduction: Prune features or use PCA to eliminate noisy input vectors.
- Early Stopping: Stop training when validation error begins to rise.
3.2 Model B: Underfitting (High Bias, Low Variance) (2.5 marks)
- Problem Identification: Model B is exhibiting Underfitting.
- Description: The model is structurally too simple to capture the underlying patterns in the dataset, leading to poor performance on both the training and test sets.
- Causes:
- Inadequate Complexity: Trying to model non-linear relationships with linear estimators (e.g., fitting a straight line to a quadratic curve).
- Insufficient Features: Not providing the model with enough explanatory variables or failing to perform useful feature transformations.
- Possible Remedies:
- Increase Complexity: Move to non-linear algorithms (e.g., Support Vector Machines, deep neural networks, or ensemble trees).
- Feature Engineering: Generate polynomial features, interaction variables, or extract domain-specific indicators to enrich the parameter space.
- Decrease Regularization: Lower the regularization coefficient () to give the model more freedom to learn data features.
SUMMARY TABLE OF REGRESSION METRICS (1 mark)
| Metric | Formula | Units | Range | When To Use | Interpretation |
|---|---|---|---|---|---|
| MAE | Original | to | Outliers aren't critical | Average absolute physical deviation | |
| MSE | Original | to | Mathematical optimization | Average squared error (outlier-sensitive) | |
| RMSE | Original | to | Standard evaluation | Standard deviation of residuals | |
| R² | Ratio | to | Assessing overall quality | Proportion of target variance explained |
KEY TAKEAWAYS (Quick Review)
✅ Least-Squares Approach:
- Minimizes the sum of squared residuals to find the optimal (slope) and (intercept).
- The regression line always passes through the sample centroid .
- Sum of OLS residuals must always sum to exactly 0.
✅ Performance Metrics:
- MAE: Linear scaling, easy to interpret, robust to outlier noise.
- MSE / RMSE: Quadratic scaling, heavily penalizes large errors.
- R²: Proportional variance explained, representing the quality of fit (0-1).
✅ Overfitting vs. Underfitting Duality:
- Overfitting: High variance, low bias. Model memorizes training noise Regularize, prune features, collect more data.
- Underfitting: High bias, low variance. Model fails to learn basic structures Enrich features, increase model complexity, decrease regularization.
ANSWER CHECKLIST
- ✅ Define SLR and write standard equation with variable definitions
- ✅ Provide calculus OLS derivative proof for both slope () and intercept ()
- ✅ Show complete calculation tables for a sample dataset
- ✅ State the final regression line equation and interpret parameters
- ✅ Explain MAE, MSE, RMSE, and with full formulas and significance
- ✅ Demonstrate step-by-step metric calculations on the dataset
- ✅ Diagnose Model A (Overfitting) and Model B (Underfitting)
- ✅ Explain definitions, causes, and remedies for overfitting and underfitting
- ✅ Display a comprehensive metric summary table
- ✅ Include an answer checklist and mark breakdown
MARK BREAKDOWN
| Component | Marks |
|---|---|
| SLR Definition & Standard Equation | 2.0 |
| Calculus Least-Squares Parameter Derivation (, ) | 3.0 |
| Step-by-Step Sample Dataset Calculation | 3.0 |
| Final Equation & Parameter Interpretations | 2.0 |
| PART 1 SUBTOTAL | 10.0 |
| MAE Definition, Calculation, and Significance | 1.5 |
| MSE Definition, Calculation, and Significance | 1.5 |
| RMSE & Equations and Calculations | 2.0 |
| PART 2 SUBTOTAL | 5.0 |
| Model A Diagnosis, Definition, Causes, and Remedies | 2.5 |
| Model B Diagnosis, Definition, Causes, and Remedies | 2.5 |
| PART 3 SUBTOTAL | 5.0 |
| TOTAL | 20.0 |
This answer scores FULL 20 marks ✅