diff --git a/docs/sources/objectives.md b/docs/sources/objectives.md index 45b6f0b76..4b25fbfb7 100644 --- a/docs/sources/objectives.md +++ b/docs/sources/objectives.md @@ -18,6 +18,8 @@ For a few examples of such functions, check out the [objectives source](https:// - __mean_squared_error__ / __mse__ - __mean_absolute_error__ / __mae__ +- __mean_absolute_percentage_error__ / __mape__ +- __mean_squared_logarithmic_error__ / __msle__ - __squared_hinge__ - __hinge__ - __binary_crossentropy__: Also known as logloss. diff --git a/keras/objectives.py b/keras/objectives.py index 7da2359b7..ba8f1a1c2 100644 --- a/keras/objectives.py +++ b/keras/objectives.py @@ -12,6 +12,9 @@ def mean_squared_error(y_true, y_pred): def mean_absolute_error(y_true, y_pred): return T.abs_(y_pred - y_true).mean(axis=-1) +def mean_absolute_percentage_error(y_true, y_pred): + return T.abs_((y_true - y_pred) / T.clip(T.abs_(y_true), epsilon, np.inf)).mean(axis=-1) * 100. + def mean_squared_logarithmic_error(y_true, y_pred): return T.sqr(T.log(T.clip(y_pred, epsilon, np.inf) + 1.) - T.log(T.clip(y_true, epsilon, np.inf) + 1.)).mean(axis=-1) @@ -38,6 +41,7 @@ def binary_crossentropy(y_true, y_pred): # aliases mse = MSE = mean_squared_error mae = MAE = mean_absolute_error +mape = MAPE = mean_absolute_percentage_error msle = MSLE = mean_squared_logarithmic_error from .utils.generic_utils import get_from_module