Is there a library function for Root mean square error (RMSE) in python?

Machine Learning

I know I could implement a root mean squared error function like this:

def rmse(predictions, targets): 

return np.sqrt(((predictions - targets) ** 2).mean())


What I'm looking for if this rmse function is implemented in a library somewhere, perhaps in scipy or scikit-learn?



sklearn >= 0.22.0

sklearn.metrics has a mean_squared_error function with a squared kwarg (defaults to True). Setting squared to False will return the RMSE.

from sklearn.metrics import mean_squared_error

rms = mean_squared_error(y_actual, y_predicted, squared=False)

sklearn < 0.22.0

sklearn.metrics has a mean_squared_error function. The RMSE is just the square root of whatever it returns.

from sklearn.metrics import mean_squared_error
from math import sqrt

rms = sqrt(mean_squared_error(y_actual, y_predicted))





Root Mean Squared Error (RMSE) is one of the library function, referred to the quadratic scoring rule which helps in measuring the average magnitude of the error. In simple terms, it is defined as the square root of the average squared differences between the prediction and the actual observations.




When it comes to the scikit learn library, sklearn.metrics has come up with a function called mean_squared_error function.



If you want to unleash your potential in this competitive field, please visit the Machine Learning course page for more information, where you can find the Machine Learning tutorials and Machine Learning frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.