diff --git a/Python/ml_metrics/elementwise.py b/Python/ml_metrics/elementwise.py index 1e4812a..d43826b 100644 --- a/Python/ml_metrics/elementwise.py +++ b/Python/ml_metrics/elementwise.py @@ -66,6 +66,29 @@ def mae(actual, predicted): """ return np.mean(ae(actual, predicted)) +def mape(actual, predicted): + """ + Computes the mean absolute percentage error. + + This function computes the mean absolute percentage error between two lists + of numbers. + BE CAREFUL: it can cause division-by-zero errors! + + Parameters + ---------- + actual : list of numbers, numpy array + The ground truth value + predicted : same type as actual + The predicted value + + Returns + ------- + score : double + The mean absolute percentage error between actual and predicted + + """ + return np.mean(np.divide(np.abs(np.array(actual) - np.array(predicted)), np.array(actual))) * 100 + def mse(actual, predicted): """ Computes the mean squared error. diff --git a/Python/setup.py b/Python/setup.py index 0b742ca..71c2909 100644 --- a/Python/setup.py +++ b/Python/setup.py @@ -3,7 +3,10 @@ from setuptools import setup import sys -requirements = [x.strip() for x in open("requirements.txt")] +requirements = [ + "numpy", + "pandas" + ] # Automatically run 2to3 for Python 3 support extra = {}