![](https://crypto4nerd.com/wp-content/uploads/2023/08/1P2pizJ2ehtZKmzwnRc-EGA.png)
Evaluate your Regression Machine Learning model properly.
Regression models form a vast pool of Machine Learning task solution choice. They are popular, oftentimes powerful, fast, and easy in implementation. Model choice is an extremely important step; however, it will be useless if you cannot evaluate the result properly. Today, we are going to look at the Regression Model Evaluation Metrics.
1. Mean Absolute Error (MAE)
Mean Absolute Error is the average taken between the original value and the predicted value. MAE shows how accurate the model predictions are; however it does not provide the information about the direction of the error ocurred. This makes it difficult to understand whether the model is underfitting or overfitting if needed. Also, MAE is not differentiable. To calculate the Mean Absolute Error in sklearn:
from sklearn.metrics import mean_absolute_error
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mean_absolute_error(y_true, y_pred)
2. Mean Squared Error (MSE)
Mean Squared Error is the average of the squares of the difference between the original values and predicted values. In MSE computation of gradient becomes easier than MAE which requires computational tools in order to compute gradients. MSE is a very effective tool in showing the outliers. MSE is recommended to use when the target is normally distributed. To calculate the Mean Squared Error in sklearn:
from sklearn.metrics import mean_squared_error
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mean_squared_error(y_true, y_pred)
3. R2 Score
R2 Score (the coefficient of determination) is a statistical measure of how close the data point is fitted to the regression line. R2 Score value fits the interval between 0 and 1, where 1 means that the model explains the variability of the response perfectly. To calculate the Mean Squared Error in sklearn:
from sklearn.metrics import r2_score
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
r2_score(y_true, y_pred)
4. Mean Squared Log Error (MSLE)
Mean Squared Log Error is the average of the square of the logarithmic difference of the actual values and predicted values. This type of evaluation metric is usually used when we don’t want to penalize huge differences in the predicted and the actual values and these predicted and actual values are considered to be huge numbers. To calculate the Mean Squared Error in sklearn:
from sklearn.metrics import mean_squared_log_error
y_true = [3, 5, 2.5, 7]
y_pred = [2.5, 5, 4, 8]
mean_squared_log_error(y_true, y_pred)
Conclusion
Evaluation metrics choice is highly important in Machine Learning. These 4 essential basic metrics will help you deal with any Regression task. Gain knowledge and experience and learn how to implement them in code!