相关疑难解决方法(0)

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

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

def rmse(predictions, targets):
    return np.sqrt(((predictions - targets) ** 2).mean())
Run Code Online (Sandbox Code Playgroud)

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

python scipy scikit-learn

129
推荐指数
8
解决办法
19万
查看次数

如何在Python中优化MAPE代码?

我需要有一个MAPE函数,但是我无法在标准包中找到它......下面,我实现了这个函数.

def mape(actual, predict): 
    tmp, n = 0.0, 0
    for i in range(0, len(actual)):
        if actual[i] <> 0:
            tmp += math.fabs(actual[i]-predict[i])/actual[i]
            n += 1
    return (tmp/n)
Run Code Online (Sandbox Code Playgroud)

我不喜欢它,它在速度方面超级不理想.如何将代码重写为Pythonic方式并提高速度?

python statistics numpy machine-learning data-science

5
推荐指数
1
解决办法
7116
查看次数