Recap and Today’s Topic
Hello! In the previous session, we learned about evaluation metrics for classification tasks, such as accuracy, recall, and the F1 score. These metrics are useful when predicting categories. Today, we’ll focus on evaluation metrics for regression tasks.
In regression tasks, where the goal is to predict continuous values (such as house prices or temperatures), different metrics are used to measure the accuracy of the predictions. Common metrics include Mean Squared Error (MSE) and Mean Absolute Error (MAE), which we will explore in detail.

What is a Regression Task?
A regression task refers to predicting continuous numerical values. Examples of regression tasks include:
- Predicting house prices
- Forecasting future temperatures
- Estimating sales revenue
In contrast, classification tasks involve assigning data to predefined categories (e.g., determining whether an email is spam or not). In regression, numerical error measures the difference between predicted and actual values, which is critical for evaluating the model’s performance.
Types of Regression Evaluation Metrics
Several key metrics are used to evaluate the accuracy of regression models. Let’s look at the most common ones.
1. Mean Squared Error (MSE)
Mean Squared Error (MSE) is the average of the squared differences between the predicted values and the actual values. MSE penalizes larger errors more severely, making it sensitive to outliers.
Formula for MSE
\[
MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i – \hat{y_i})^2
\]
Where:
\(n\) is the number of samples,
\(y_i\) is the actual value,
\(\hat{y_i}\) is the predicted value.
Because the errors are squared, larger deviations contribute disproportionately to the MSE, which makes it useful when large errors are particularly problematic.
2. Mean Absolute Error (MAE)
Mean Absolute Error (MAE) measures the average absolute differences between predicted and actual values. Unlike MSE, it does not square the errors, so it is less sensitive to outliers.
Formula for MAE
\[
MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i – \hat{y_i}|
\]
Since MAE treats all errors equally, it provides a more balanced view of overall error without giving excessive weight to large outliers.
3. Mean Squared Logarithmic Error (MSLE)
Mean Squared Logarithmic Error (MSLE) is similar to MSE but uses the logarithms of the values before squaring. This reduces the impact of large differences and emphasizes the relative error.
Formula for MSLE
\[
MSLE = \frac{1}{n} \sum_{i=1}^{n} (\log(1 + y_i) – \log(1 + \hat{y_i}))^2
\]
MSLE is particularly useful when the ratio between the predicted and actual values is important, as it tempers the impact of larger errors.
4. Coefficient of Determination (R²)
R² (Coefficient of Determination) measures how well the model explains the variance in the data. R² ranges from 0 to 1, with higher values indicating that the model explains the data well.
Formula for R²
\[
R^2 = 1 – \frac{\sum_{i=1}^{n} (y_i – \hat{y_i})^2}{\sum_{i=1}^{n} (y_i – \bar{y})^2}
\]
Where:
\( \bar{y} \) is the mean of the actual values.
An R² value close to 1 indicates that the model makes very accurate predictions, while values near 0 indicate poor predictive performance.
5. Huber Loss
Huber Loss is a hybrid metric that combines the strengths of MSE and MAE. For smaller errors, it behaves like MSE, while for larger errors, it switches to MAE, reducing the impact of outliers.
Formula for Huber Loss
\[
L_{\delta}(a) =
\begin{cases}
\frac{1}{2} a^2 & \text{if } |a| \leq \delta, \
\delta (|a| – \frac{1}{2} \delta) & \text{otherwise.}
\end{cases}
\]
Huber Loss is particularly useful when you want to mitigate the impact of outliers while maintaining a high level of accuracy for smaller errors.
Choosing the Right Metric
The choice of evaluation metric depends on the goals of the task. Below are some guidelines for selecting the appropriate metric based on the problem at hand.
1. When Outliers Matter
If outliers are important and should be heavily penalized, MSE is the most appropriate metric. The squaring of errors makes MSE sensitive to large deviations, which can be useful when large errors are especially problematic.
2. When Reducing the Impact of Outliers
When you want to reduce the influence of outliers, MAE is a better choice. MAE treats all errors equally, so large errors do not disproportionately affect the overall evaluation.
3. When Ratios or Growth Rates Matter
For tasks where the ratio between predicted and actual values is critical, such as growth rate predictions, MSLE is ideal. MSLE reduces the impact of large errors and focuses more on the relative difference between values.
Practical Applications
House Price Prediction
For predicting house prices, MAE and MSE are often used. Since housing data can contain significant outliers, such as luxury homes, MSE may be useful when focusing on those outliers, while MAE can provide a more balanced evaluation of overall error.
Sales Forecasting
In sales forecasting, MSLE is particularly useful since it emphasizes relative changes, such as percentage growth in sales. This makes it effective for predicting revenue or sales trends where the proportional error matters.
Weather Forecasting
For tasks like temperature prediction, where outliers can distort the evaluation, Huber Loss is often used. It helps minimize the effect of extreme values while maintaining accuracy for most predictions.
Conclusion
In this lesson, we explored key evaluation metrics for regression tasks, including MSE, MAE, MSLE, and R². These metrics help assess how accurately a model predicts continuous values. Choosing the right metric depends on the task’s focus, such as handling outliers or considering ratios.
Next time, we’ll wrap up Chapter 2 with a summary and comprehension check, reviewing everything we’ve learned so far about regression and classification problems. Stay tuned!
Glossary:
- Regression Task: A task where the goal is to predict continuous values rather than categories.
- Outliers: Data points that are significantly different from other observations and may skew results.
Comments