-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from UBC-MDS/mae
Add Mean Absolute Error (MAE) function with detailed documentation
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Mean Absolute Error (MAE) calculation | ||
def mean_absolute_error(y_true, y_pred): | ||
""" | ||
Calculate the Mean Absolute Error (MAE) metric for regression. | ||
This function computes the average absolute difference between the predicted values (`y_pred`) | ||
and the actual values (`y_true`). It measures the magnitude of errors in prediction, providing | ||
a straightforward evaluation of a model's accuracy. | ||
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 Error. | ||
Notes: | ||
------ | ||
MAE is defined as: | ||
MAE = (1 / n) * sum(|y_true - y_pred|) | ||
where n is the number of observations. | ||
Examples: | ||
--------- | ||
>>> y_true = [100, 200, 300] | ||
>>> y_pred = [110, 190, 290] | ||
>>> mean_absolute_error(y_true, y_pred) | ||
10.0 | ||
""" |