From 3a987162dd74c4159e8980abcd89036d4c873bc8 Mon Sep 17 00:00:00 2001 From: Marco De Nadai Date: Wed, 11 Jun 2014 22:05:04 +0200 Subject: [PATCH 1/4] pip and easy_install setup fixed --- Python/setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 = {} From 5bd0bd7fcb607fdabb310deaa2cec686b676d0c2 Mon Sep 17 00:00:00 2001 From: Marco De Nadai Date: Thu, 12 Jun 2014 01:39:00 +0200 Subject: [PATCH 2/4] Added MAPE metrics --- Python/ml_metrics/elementwise.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Python/ml_metrics/elementwise.py b/Python/ml_metrics/elementwise.py index 1e4812a..9f8179f 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.abs(np.divide((np.array(actual) - np.array(predicted)), predicted))) * 100 + def mse(actual, predicted): """ Computes the mean squared error. From 12c8c4647491093a564c8a3039c45a6a218832ec Mon Sep 17 00:00:00 2001 From: Marco De Nadai Date: Sat, 26 Jul 2014 21:38:33 +0200 Subject: [PATCH 3/4] Revert "Added MAPE metrics" This reverts commit 5bd0bd7fcb607fdabb310deaa2cec686b676d0c2. --- Python/ml_metrics/elementwise.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/Python/ml_metrics/elementwise.py b/Python/ml_metrics/elementwise.py index 9f8179f..1e4812a 100644 --- a/Python/ml_metrics/elementwise.py +++ b/Python/ml_metrics/elementwise.py @@ -66,29 +66,6 @@ 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.abs(np.divide((np.array(actual) - np.array(predicted)), predicted))) * 100 - def mse(actual, predicted): """ Computes the mean squared error. From 73b2ea560a6a8c925baa5b15008a4afa1b5db5f3 Mon Sep 17 00:00:00 2001 From: Marco De Nadai Date: Sat, 26 Jul 2014 21:43:33 +0200 Subject: [PATCH 4/4] Added MAPE, standard for electric forecasting --- Python/ml_metrics/elementwise.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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.