python - python中是否有用于均方根误差(RMSE)的库函数?

标签 python scikit-learn scipy

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

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

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

最佳答案

sklearn >= 0.22.0

sklearn.metrics 有一个 mean_squared_error 函数和一个 squared kwarg(默认为 True)。将 squared 设置为 False 将返回 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 只是它返回的平方根。

from sklearn.metrics import mean_squared_error
from math import sqrt

rms = sqrt(mean_squared_error(y_actual, y_predicted))

关于python - python中是否有用于均方根误差(RMSE)的库函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17197492/

相关文章:

python - 解析多行日志文件,其中的上下文更改行

python - 我可以 pip 安装 cython 模块并使其 pxds 可用于 cimport 吗?

python - 在Python中对可变长度数组进行分类

python - 类型错误 : 'dia_matrix' object has no attribute '__getitem__' - Python

python - 如何在python中获取由三个坐标定义的平面的倾斜角度?

python - 具有 Crispy-forms VariableDoesNotExist 的 Django

python - 来自两个 pandas DataFrame 的不相交的记录集

python - 将 scikit 缩放数据映射回 ID

python - 使用 KernelExplainer(SHAP 工具)进行 Pipeline 和多类分类

python - Scipysolve_banded矩阵使用的求解方法