Skip to content
Open

Mape #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Python/ml_metrics/elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion Python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down