Cover
02 - Linear Regression and Evaluation (revised).pdf
📚 02 - Linear Regression and Evaluation (revised).pdf
Brief overview
This document introduces the fundamental concepts of linear regression for predictive modeling and details essential methods for evaluating model performance. Understanding these topics is crucial for building accurate and reliable predictive systems.
Key points
- Understanding the identification of regression tasks and the construction of simple prediction rules.
- Learning how to build and interpret straight-line linear models, including slope and intercept.
- Calculating residuals and mean squared error (MSE) to measure prediction errors.
- Differentiating between training and new-data performance, and understanding underfitting and overfitting.
- Exploring the roles of training, validation, and test data in honest model evaluation.
1. Understanding linear regression
1.1 Regression tasks and prediction rules
- Regression task: Predicts a numerical, measurable quantity.
- Example: Predicting delivery time in minutes.
- Test: Does a value between two possible targets make sense? (e.g., 27.5 degrees Celsius is meaningful).
- Classification task: Predicts a category.
- Example: Predicting if a message is spam.
- Test: A value halfway between two categories is not meaningful (e.g., halfway between "tuna" and "salmon").
- Identifiers: Numbers that are labels, not quantities (e.g., phone numbers, postal codes). Averaging them doesn't make sense.
Regression tasks predict measurable quantities.
- Prediction rule: A simple rule to estimate an output.
- Example:
predicted time = 5 minutes (prep) + 3 minutes * distance (km). - Features (x): The input variable used for prediction (e.g., distance).
- Predicted output (ŷ): The estimated output value. The hat (^) signifies a prediction.
| Input (x) | Preparation (5 min) | Travel allowance (3x) | Predicted Time (ŷ) |
|---|---|---|---|
| 0 km | 5 min | 0 min | 5 min |
| 1 km | 5 min | 3 min | 8 min |
| 2 km | 5 min | 6 min | 11 min |
| 3 km | 5 min | 9 min | 14 min |
1## 1.2 The straight-line model
- General straight-line model:
ŷ = α + βx. x: Input or feature.ŷ: Predicted output.α(alpha): The intercept. It's the predicted value whenx = 0.β(beta): The slope. It's the predicted change inŷwhenxincreases by 1.- Units of slope: output-unit per input-unit (e.g., minutes per kilometer).
- Parameter interpretation:
- Slope: Controls how steeply the line rises or falls.
- Intercept: Slides the entire line up or down.
The slope tells you how much the prediction changes for each unit increase in the input.
1.2.1 Making predictions with the model
- Prediction example: For
ŷ = 5 + 3x, predict time at 6 km. - Substitute
x = 6:ŷ = 5 + 3. - Calculate:
ŷ = 5 + 18 = 23minutes 2 3.
1.3 Understanding prediction errors
- Actual value (y): The true observed output.
- Residual: The difference between the actual value and the predicted value.
- Formula:
r = y - ŷ. - Residual interpretation:
r > 0: The model predicted too low; actual is higher than predicted.r < 0: The model predicted too high; actual is lower than predicted.r = 0: The prediction was exact for that observation.
A positive residual means your model underestimated the true value.
- Problem with adding residuals: Positive and negative residuals can cancel each other out, hiding errors.
- Mean Squared Error (MSE): Combines errors by squaring them to prevent cancellation and then averaging.
- Formula:
MSE = (1/n) * Σ(yi - ŷi)². n: Number of observations.yi: Actual value for observationi.ŷi: Predicted value for observationi.Σ: Summation symbol.- MSE unit: Squared units of the target variable (e.g.,
minutes²). - MSE interpretation: A lower MSE indicates a model with closer predictions on the same data.




