Member-only story
Interview Question: calculate RMSE for a built model in Python
Root mean squared error (RMSE) is a goodness of fit test that measures the quality of regression models in machine learning. This is one metric that is used to test how well a machine learning model functions when predicting on a regression dataset. It is for that reason that an individual is likely to encounter a question regarding RMSE when they are at an interview.
RMSE is the square root of the sum of the squared differences between the predicted and observed values and is divided by the number of observations.
The formula for this metric is:-
In this post I have included three ways that the RMSE can be calculated when measuring the error between predicted values and actual values.
The first way to calculate RMSE, and perhaps my favourite way, is to use Python’s numerical library, numpy:-
- Calculate the mean squared error (MSE) by taking the square of the mean of the predicted values less the actual values.
- Calculate the RMSE by taking the square root of the RMSE.
For those individuals who like to use Python’s machine learning library, sklearn, there is a method that can be used to calculate the RMSE. In order to calculate the RMSE, the square root of sklearn’s function…