Skip to content

Commit 96b621f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3f34cd4 commit 96b621f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

machine_learning/loss_functions.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -667,26 +667,26 @@ def mean_absolute_percentage_error(
667667
y_true: np.ndarray, y_pred: np.ndarray, epsilon: float = 1e-15
668668
) -> float:
669669
"""
670-
Calculate the Mean Absolute Percentage Error (MAPE) between y_true and y_pred.
671-
  MAPE is calculated by dividing the absolute error by the absolute value of
672-
the actual measurement and then averaging.
673-
SMAPE = (1/n) * Σ( |y_true - y_pred| / |y_true|)
674-
Reference:
675-
https://en.wikipedia.org/wiki/Mean_absolute_percentage_error
676-
Parameters:
677-
- y_true: The true values (ground truth)
678-
- y_pred: The predicted values
679-
- epsilon: Small constant to avoid division by zero
680-
>>> true_values = np.array([100, 200, 300, 400])
681-
>>> predicted_values = np.array([110, 190, 310, 420])
682-
>>> float(symmetric_mean_absolute_percentage_error(true_values, predicted_values))
683-
0.058333333333333334
684-
>>> true_labels = np.array([100, 200, 300])
685-
>>> predicted_probs = np.array([110, 190, 310, 420])
686-
>>> symmetric_mean_absolute_percentage_error(true_labels, predicted_probs)
687-
Traceback (most recent call last):
688-
...
689-
ValueError: Input arrays must have the same length.
670+
Calculate the Mean Absolute Percentage Error (MAPE) between y_true and y_pred.
671+
MAPE is calculated by dividing the absolute error by the absolute value of
672+
the actual measurement and then averaging.
673+
SMAPE = (1/n) * Σ( |y_true - y_pred| / |y_true|)
674+
Reference:
675+
https://en.wikipedia.org/wiki/Mean_absolute_percentage_error
676+
Parameters:
677+
- y_true: The true values (ground truth)
678+
- y_pred: The predicted values
679+
- epsilon: Small constant to avoid division by zero
680+
>>> true_values = np.array([100, 200, 300, 400])
681+
>>> predicted_values = np.array([110, 190, 310, 420])
682+
>>> float(symmetric_mean_absolute_percentage_error(true_values, predicted_values))
683+
0.058333333333333334
684+
>>> true_labels = np.array([100, 200, 300])
685+
>>> predicted_probs = np.array([110, 190, 310, 420])
686+
>>> symmetric_mean_absolute_percentage_error(true_labels, predicted_probs)
687+
Traceback (most recent call last):
688+
...
689+
ValueError: Input arrays must have the same length.
690690
"""
691691
if len(y_true) != len(y_pred):
692692
raise ValueError("Input arrays must have the same length.")

0 commit comments

Comments
 (0)