Skip to content

Commit

Permalink
Merge pull request #15 from UBC-MDS/mape
Browse files Browse the repository at this point in the history
added MAPE function and renamed MSE function
  • Loading branch information
gracez-20 authored Jan 10, 2025
2 parents a4fd7d3 + d21a0df commit 8dfa085
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
35 changes: 35 additions & 0 deletions src/matrics_calculator/MAPE.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Mean Absolute Percentage Error (MAPE) calculation
def mean_absolute_percentage_error(y_true, y_pred):
"""
Calculate the Mean Absolute Percentage Error (MAPE) metric for regression.
This function computes the average percentage difference between the predicted values (`y_pred`)
and the actual values (`y_true`). It measures the relative magnitude of errors in prediction,
expressed as a percentage. MAPE is widely used to evaluate regression models, especially when
relative error matters more than absolute error.
Parameters:
----------
y_true : array-like
True values of the target variable.
y_pred : array-like
Predicted values from the model.
Returns:
-------
float
The Mean Absolute Percentage Error (as a percentage).
Notes:
------
MAPE is defined as:
MAPE = (1 / n) * sum(|(y_true - y_pred) / y_true|) * 100
where n is the number of observations.
Examples:
---------
>>> y_true = [100, 200, 300]
>>> y_pred = [110, 190, 290]
>>> mean_absolute_percentage_error(y_true, y_pred)
3.3333
"""
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@







# Mean Squared Error (MSE) calculation
def mean_squared_error(y_true, y_pred):
"""
Expand Down

0 comments on commit 8dfa085

Please sign in to comment.