Commit 23a920a8 authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Fixed division by 0 during computation of MAPE.

parent cfdd8f94
Pipeline #3059 failed with stage
in 17 minutes and 40 seconds
......@@ -1260,7 +1260,13 @@ class ClusterClassifier_Generator(object):
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_true - y_pred) / y_true), axis=0) * 100 # TODO avoid division by 0
# avoid division by 0
if 0 in y_true:
y_true = y_true.astype(np.float)
y_true[y_true == 0] = np.nan
return np.nanmean(np.abs((y_true - y_pred) / y_true), axis=0) * 100
###########################
# compute RMSE, MAE, MAPE #
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment