我知道我可以实现这样的均方根误差函数:
def rmse(predictions, targets):
return np.sqrt(((predictions - targets) ** 2).mean())
Run Code Online (Sandbox Code Playgroud)
如果这个rmse函数在某个库中实现,可能是scipy或scikit-learn,我正在寻找什么?
我需要有一个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方式并提高速度?