![](https://crypto4nerd.com/wp-content/uploads/2023/08/1LP0b0BARRfo5dHlKhOlSrg-1024x512.png)
Hello Everyone 👋, when developing regression models on our datasets, we must analyze the performance of the models we create in order to select the best model. In this article, we will learn about the five regression metrics listed below, which will help us measure how well our model’s predictions match the actual target values as well as code implementation.
- Mean Absolute Error(MAE)
- Mean Squared Error (MSE)
- Root Mean Squared Error (RMSE)
- R2-score (Coefficient of Determination)
- Adjusted R2-score
The mean absolute error measures the average absolute difference between the actual and predicted values. The MAE formula is as follows:
Here, n is the number of data points, yi is the actual value, and Ĺ·i is the predicted value. The model with a lower MAE value is performing better than the model with a relatively high MAE value.
Pros
- The MAE value is measured in the same unit as the dependent variable.
- MAE is not affected by outliers.
Cons
Because the modulus function graph is not differentiable at x = 0. As a result, we cannot utilize the MAE in optimization algorithms where the loss function must be differentiated.
MSE is calculated as the sum of the squared differences between the actual and predicted values. MSE can be calculated using the following formula:
Here, n is the number of data points, yi is the actual value, and Ĺ·i is the predicted value. Like MAE, a lower MSE score indicates that the model is doing better on the given data points.
Pros
Since we can easily differentiate the square function, we can use it as a loss function for optimization techniques (Gradient Descent, for example).
Cons
- Unlike MAE, MSE doesn’t have the same scale as the dependent variable, which makes it hard to interpret the final value.
- MSE is not robust to outliers.
RMSE is the square root of MSE and is often used because it is in the same units as the target variable. It gives a greater understanding of the scale of the error.
Here, n is the number of data points, yi is the actual value, and Ĺ·i is the predicted value.
Pros
When compared to the MSE value, the RMSE value is easier to interpret.
Cons:
Like MSE, RMSE is sensitive to outliers.
The R2 score, also known as the coefficient of determination, is used to evaluate the accuracy of a linear regression model. It is the amount of variation in the dependent variable (target) that can be explained using the model’s independent variables (features). The R2 score formula is as follows:
The above formula can be seen as a measure of how well our regression line is performing as compared to the average or mean line.
The R2 score ranges from 0 to 1, with higher values indicating a better fit. A value of 1 means the model explains all the variance in the data, while 0 means it explains none.
When we add irrelevant features or columns to our model, the R2 score either increases or stays the same, which is incorrect. The R2 score should ideally decrease for irrelevant features. To address this issue, we use an R2 score that penalizes the inclusion of irrelevant features. The formula for the adjusted R2 score is as follows:
Now that we’ve covered the fundamentals of regression metrics, let’s look at how they’re implemented in code. We’ll also observe how adding an irrelevant feature increases the R2 score while decreasing the adjusted R2 score. We will also examine how adding the required features will improve the adjusted R2 score.
Congratulations !!! on understanding Regression Metrics concepts and the code implementation using the Sklearn library.
Thank you for taking the time to read this post. If you liked this read, hit the Clapđź‘Ź button and share it with others. If you have any questions, please leave them in the comments section, and I will do my best to answer them.
You can also check out other interesting articles under my Medium profile. If you would like to dive deeper into topics like this, explore more of my writings, or be the first to know when I publish something new, consider following me.
You can also connect with me on LinkedIn, Facebook, and Instagram.
Until next time, Adios Amigo!!!!