How to optimize MAPE code in Python?

后端 未结 2 789
小蘑菇
小蘑菇 2020-12-30 12:43

I need to have a MAPE function, however I was not able to find it in standard packages ... Below, my implementation of this function.

def mape(actual, predic         


        
2条回答
  •  余生分开走
    2020-12-30 13:03

    Another similar way of doing it using masked_Arrays to mask division by zero is:

    import numpy.ma as ma
    masked_actual = ma.masked_array(actual, mask=actual==0)
    MAPE = (np.fabs(masked_actual - predict)/masked_actual).mean()
    

提交回复
热议问题