Where is T (threshold) defined

Maybe I missed this, but in the MAPE description, a variable was mentioned in the MAPE definition and I don’t see it anywhere in the project description.

It’s on the problem description page:

The value of T is 290000. We’ll make that more prominent, thanks!

Thanks for the quick response. My mistake for not using more effort to find it.

this is mean adjusted absolute percent error. A variant from MAPE.

MAPE custom code is below:
def mean_absolute_percentage_error(y_true, y_pred):
y_true, y_pred = np.array(y_true), np.array(y_pred)
return np.mean(np.abs((y_test - y_pred) / (y_pred))) * 100

However, I am having hard time implementing the code for mean adjusted absolute percent error. Can someone share the code please?

def mape(y_actual, y_pred):
return np.average(np.abs(y_pred - y_actual) / np.maximum(np.abs(y_actual), 290000))

Thanks Hakymulla. I have the same code but doesn’t work with Keras Tensorflow back-end implementation of custom loss function.

ooh, it wont work. find a way to work around it with tensor and not numpy array

If you would just look into the github of Keras, you can find the implementation of the mean_absolute_percentage_error there (https://github.com/keras-team/keras/blob/master/keras/losses.py):

def mean_absolute_percentage_error(y_true, y_pred):
    diff = K.abs((y_true - y_pred) / K.clip(K.abs(y_true),
                                            K.epsilon(),
                                            None))
    return 100. * K.mean(diff, axis=-1)

Just change that clip and you’re done.

1 Like

Thanks Gillesvdw. custom code in keras works well.