Skip to content

Commit

Permalink
Merge pull request #172 from kwanit1142/master
Browse files Browse the repository at this point in the history
Added Mean Absolute Percentage Error
  • Loading branch information
agrawalshubham01 authored Apr 12, 2021
2 parents 1ecece2 + 5271f42 commit 271e10c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions MLlib/loss_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,34 @@ def loss(X, Y, W):
sigmoid = Sigmoid()
H = sigmoid.activations(np.dot(X, W).T)
return np.sqrt((1 / M) * (np.sum(np.log(Y + 1) - np.log(H + 1))))


class MeanAbsolutePrecentageError():
"""""
Calcute Mean Absolute Percentage Loss
"""

@staticmethod
def loss(X, Y, W):
"""
Calculate Mean Squared Log Loss
PARAMETERS
==========
X:ndarray(dtype=float,ndim=1)
input vector
Y:ndarray(dtype=float)
output vector
W:ndarray(dtype=float)
Weights
RETURNS
=======
array of Mean Absolute Percentage Loss
"""

y_pred = np.dot(X, W).T
L = np.sum(np.true_divide((np.abs(Y - y_pred) * 100), Y)) / X.shape[0]
return L
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ Follow the following steps to get started with contributing to the repository.
| Log_cosh | [loss_func.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/loss_func.py#L248) | | | F1 Score | [metrics.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/metrics.py#L85)
| Huber | [loss_func.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/loss_func.py#L300) | | | F-B Theta | [metrics.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/metrics.py#L88)
| Mean Squared Log Error | [loss_func.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/loss_func.py#L367) | | | Specificity | [metrics.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/metrics.py#L86)

| Mean Absolute Percentage Error | [loss_func.py](https://github.com/RoboticsClubIITJ/ML-DL-implementation/blob/master/MLlib/loss_func.py#L399)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
install_requires=[
'numpy>=1.18.0',
'matplotlib>=3.0.0',
'scipy'
'scipy',
'pandas'
],
)

0 comments on commit 271e10c

Please sign in to comment.