diff --git a/MLlib/loss_func.py b/MLlib/loss_func.py index 9ad3465..f182f09 100644 --- a/MLlib/loss_func.py +++ b/MLlib/loss_func.py @@ -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 diff --git a/README.md b/README.md index d74adba..22b962e 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/setup.py b/setup.py index 18ab4fe..738e001 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ install_requires=[ 'numpy>=1.18.0', 'matplotlib>=3.0.0', - 'scipy' + 'scipy', 'pandas' ], )