python中是否有均方根误差(RMSE)的库函数? [英] Is there a library function for Root mean square error (RMSE) in python?

查看:95
本文介绍了python中是否有均方根误差(RMSE)的库函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以实现这样的均方根误差函数:

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

def rmse(predictions, targets):
    return np.sqrt(((predictions - targets) ** 2).mean())

如果这个 rmse 函数是在某个库中实现的,可能是在 scipy 或 scikit-learn 中,我在寻找什么?

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 有一个 mean_squared_error 函数和一个 squared kwarg(默认为 True).将 squared 设置为 False 将返回 RMSE.

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 有一个 mean_squared_error 函数.RMSE 只是它返回值的平方根.

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))

这篇关于python中是否有均方根误差(RMSE)的库函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆