MSE vs MAE in Machine Learning

Abdul Baasith
3 min readSep 3, 2021

MSE (Mean squared Error)

MSE is calculated by taking the average of the square of the difference between the original and predicted values of the data. Mean square error is always positive and a value closer to 0 or a lower value is better. Let’s see how this this is calculated;

MSE :

  • 30 * -30 = 900

There fore 2425 / 5 = 485

so N is the total number of rows in the dataset. The sigma symbol denotes that the difference between actual and predicted values taken on every i value ranging from 1 to n.

Root mean squared can be calculated as

from sklearn.metrics import mean_squared_error

actual_values = [4, 0.5, 2, 9]
predicted_values = [2.5, 0.0, 2, 8]

mean_squared_error(actual_values, predicted_values)

MAE (Mean Absolute Error)

This error basically is the absolute difference between the actual or true values and the values that are predicted. The mean absolute error is a common measure of estimate error in time series analysis.

we find out the difference between the actual value and predicted values for all 5 values and take their positive value. So even if the difference between actual and predicted value is negative, we take positive value for calculation.

MAE = True values — Predicted values

there for 105 / 5 = 21

MAE takes the average of this error from every sample in a dataset and gives the output . MAE is more robust to data with outliers if its fed with a value that the train is not seen simply it may perform extremely well on seen data but might fail miserably when it encounters real, unseen data.

Mean absolute Error can be calculated as

from sklearn.metrics import mean_absolute_error

# predicting home prices
predicted_home_prices = house_model.predict(X)
mean_absolute_error(y, predicted_home_prices)

Now we all will be thing what will the MAE and MSE mean for a machine learning model

MAE: It is not very sensitive to outliers in comparison to MSE since it doesn’t punish huge errors. It is usually used when the performance is measured on continuous variable data. It gives a linear value, which averages the weighted individual differences equally. The lower the value, better is the model’s performance.

MSE: It is one of the most commonly used metrics, but least useful when a single bad prediction would ruin the entire model’s predicting abilities, i.e when the dataset contains a lot of noise. It is most useful when the dataset contains outliers, or unexpected values (too high or too low values).Values which are closer to zero are better

Hope the tutorial was helpful. If there is anything we missed out, do let us know through comments.😇

Like and share

--

--

Abdul Baasith

Hi there iam Abdul Baasith Software Engineer .I'am Typically a person who thinks out of the box . If your tool is a hammer then every problem look like a nail