SAMPLE EXAM ANSWER: Linear Regression & Performance Metrics
Question: Explain how linear regression works using the mathematical expression for a sample dataset? Also, what are the different performance evaluation metrics, and how do they work?
Marks: 10 marks | Time: 15 minutes
✅ COMPLETE EXAM ANSWER
PART 1: LINEAR REGRESSION WITH MATHEMATICAL EXPRESSION (6 marks)
1.1 Definition (1 mark)
Linear regression is a supervised learning algorithm used to predict continuous numerical values based on one or more input features. It establishes a linear relationship between independent variables (features) and a dependent variable (target) by fitting the best-fit line through the data points.
1.2 Mathematical Expression (2 marks)
The linear regression equation is represented as:
Where:
- y = Dependent variable (target/output)
- β₀ = Intercept (value of y when all x = 0)
- β₁, β₂, ..., βₙ = Coefficients/slopes (weights for each feature)
- x₁, x₂, ..., xₙ = Independent variables (features/input)
- ε = Error term (residuals/difference between actual and predicted)
- n = Number of features
For Simple Linear Regression (1 feature):
Where is the predicted value.
1.3 Coefficient Calculation (1 mark)
The coefficients are calculated using the Least Squares Method to minimize the Sum of Squared Residuals (SSR):
Where:
- = Mean of x values
- = Mean of y values
- = Covariance between x and y
- = Variance of x
1.4 Worked Example with Sample Dataset (2 marks)
Problem: Predict Student's Exam Score based on Hours Studied
| Student | Hours Studied (x) | Exam Score (y) |
|---|---|---|
| 1 | 2 | 40 |
| 2 | 3 | 50 |
| 3 | 4 | 60 |
| 4 | 5 | 70 |
| 5 | 6 | 80 |
Step 1: Calculate means
Step 2: Calculate numerator
| x | y | (x - 4) | (y - 60) | (x - 4)(y - 60) |
|---|---|---|---|---|
| 2 | 40 | -2 | -20 | 40 |
| 3 | 50 | -1 | -10 | 10 |
| 4 | 60 | 0 | 0 | 0 |
| 5 | 70 | 1 | 10 | 10 |
| 6 | 80 | 2 | 20 | 40 |
| Sum | 100 |
Numerator = 100
Step 3: Calculate denominator
| x | (x - 4) | (x - 4)² |
|---|---|---|
| 2 | -2 | 4 |
| 3 | -1 | 1 |
| 4 | 0 | 0 |
| 5 | 1 | 1 |
| 6 | 2 | 4 |
| Sum | 10 |
Denominator = 10
Step 4: Calculate β₁ (slope)
Interpretation: For every 1 additional hour studied, exam score increases by 10 points.
Step 5: Calculate β₀ (intercept)
Interpretation: If student studies 0 hours, predicted score is 20 points (baseline).
Step 6: Final Regression Equation
Prediction Examples:
- If x = 3 hours: points
- If x = 7 hours: points
- If x = 2.5 hours: points
PART 2: PERFORMANCE EVALUATION METRICS (4 marks)
For regression models, we evaluate performance using error-based metrics:
Metric 1: MAE - Mean Absolute Error (1 mark)
Interpretation:
- Average of absolute differences between actual and predicted values
- Units: Same as target variable (e.g., points)
- Advantage: Robust to outliers; easy to interpret
- Range: 0 to ∞ (lower is better)
Example from dataset:
| Actual | Predicted | Error | Absolute Error |
|---|---|---|---|
| 40 | 30 | -10 | 10 |
| 50 | 50 | 0 | 0 |
| 60 | 60 | 0 | 0 |
| 70 | 70 | 0 | 0 |
| 80 | 90 | 10 | 10 |
MAE = (10 + 0 + 0 + 0 + 10) / 5 = 4 points
Interpretation: On average, predictions are off by 4 points.
Metric 2: MSE - Mean Squared Error (1 mark)
Interpretation:
- Average of squared errors
- Units: Square of target variable (e.g., points²)
- Advantage: Penalizes large errors heavily
- Disadvantage: Hard to interpret; affected by outliers
- Range: 0 to ∞ (lower is better)
Example:
| Actual | Predicted | Error | Squared Error |
|---|---|---|---|
| 40 | 30 | -10 | 100 |
| 50 | 50 | 0 | 0 |
| 60 | 60 | 0 | 0 |
| 70 | 70 | 0 | 0 |
| 80 | 90 | 10 | 100 |
MSE = (100 + 0 + 0 + 0 + 100) / 5 = 40 points²
Metric 3: RMSE - Root Mean Squared Error (1 mark)
Interpretation:
- Square root of MSE
- Units: Same as target variable (back to original scale)
- Advantage: Interpretable; penalizes outliers; most common metric
- Range: 0 to ∞ (lower is better)
Example:
Interpretation: On average, predictions deviate by 6.32 points (slightly higher than MAE due to outlier penalization).
When to use:
- MAE vs RMSE: If you want to penalize large errors more → use RMSE
- If all errors equally important → use MAE
Metric 4: R² - Coefficient of Determination (1 mark)
Interpretation:
- What % of variance in y is explained by the model?
- Range: 0 to 1 (higher is better)
- R² = 1.0 → Perfect fit
- R² = 0.5 → Model explains 50% of variance
- R² = 0 → Model explains nothing (as good as predicting mean)
Calculation Example:
(Residual Sum of Squares):
(Total Sum of Squares):
Interpretation: Model explains 80% of the variance in exam scores. This is a good fit.
Metric 5: Adjusted R² (Mentioned but not always required)
Where:
- n = number of samples
- p = number of features
When to use: For multiple regression; penalizes adding unnecessary features.
SUMMARY TABLE OF METRICS (1 mark)
| Metric | Formula | Units | Range | When To Use | Interpretation |
|---|---|---|---|---|---|
| MAE | Σ|y - ŷ|/n | Original | 0-∞ | Outliers not critical | Avg absolute deviation |
| MSE | Σ(y - ŷ)²/n | Original² | 0-∞ | Penalize large errors | Avg squared error |
| RMSE | √MSE | Original | 0-∞ | Most common | Avg deviation (interpretable) |
| R² | 1 - SS_res/SS_tot | Ratio | 0-1 | Overall fit quality | % variance explained |
| Adj R² | Modified R² | Ratio | 0-1 | Multiple regression | Penalizes extra features |
KEY TAKEAWAYS (Quick Review)
✅ Linear Regression:
- Finds best-fit line minimizing Sum of Squared Residuals
- Simple formula: y = β₀ + β₁x
- Always show calculation steps with actual numbers
✅ Performance Metrics:
- MAE: Easy to interpret, robust to outliers
- MSE/RMSE: Standard practice, penalizes large errors
- R²: Tells how good the fit is (0-1 scale)
- Choose metrics based on whether outliers matter
✅ Exam Tips:
- Always show coefficient calculations step-by-step
- Use real numbers in worked examples
- Explain what each metric means in context
- Compare metrics when appropriate
ANSWER CHECKLIST
- ✅ Define linear regression clearly
- ✅ Write mathematical formula with variable definitions
- ✅ Show coefficient calculation method (Least Squares)
- ✅ Provide complete worked example with sample dataset (5+ data points)
- ✅ Calculate β₁ and β₀ with all arithmetic steps
- ✅ Write final equation with interpretation
- ✅ Explain 5 evaluation metrics with formulas
- ✅ Provide calculation example for at least MAE, RMSE, R²
- ✅ Compare when to use each metric
- ✅ Show summary table
MARK BREAKDOWN
| Component | Marks |
|---|---|
| Definition + formula | 1 |
| Mathematical expression explanation | 2 |
| Coefficient calculation method | 1 |
| Worked example (step-by-step) | 2 |
| Evaluation metrics explanation | 1 |
| Metric calculations with examples | 2 |
| Interpretation & when to use | 1 |
| Total | 10 |
This answer scores FULL 10 marks ✅
When writing in exam, allocate 15 minutes for this question. Write clearly, show all steps, and include interpretations.