diff --git a/ML/Algorithms/Losses/MeanAbsoluteError/MeanAbsoluteError.py b/ML/Algorithms/Losses/MeanAbsoluteError/MeanAbsoluteError.py new file mode 100644 index 0000000..30112db --- /dev/null +++ b/ML/Algorithms/Losses/MeanAbsoluteError/MeanAbsoluteError.py @@ -0,0 +1,15 @@ +# Algorithms/Losses/mean_squared_error.py +import numpy as np + +def mean_absolute_error(y_true, y_pred): + """ + Calculate the mean absolute error between true and predicted values. + + Parameters: + - y_true: True target values (numpy array). + - y_pred: Predicted values (numpy array). + + Returns: + - Mean absolute error (float). + """ + return (np.absolute(y_true - y_pred)).mean() \ No newline at end of file diff --git a/ML/Algorithms/Losses/RootMeanSquaredError/RootMeanSquaredError.py b/ML/Algorithms/Losses/RootMeanSquaredError/RootMeanSquaredError.py new file mode 100644 index 0000000..db2e566 --- /dev/null +++ b/ML/Algorithms/Losses/RootMeanSquaredError/RootMeanSquaredError.py @@ -0,0 +1,16 @@ +import numpy as np +import math as mt + +def root_mean_squared_error(y_true,y_pred): + """ + Calculate the root mean squared error between true and predicted values. + + Parameters: + - y_true: True target values (numpy array). + - y_pred: Predicted values (numpy array). + + Returns: + - Root Mean squared error (float). + """ + return mt.sqrt(np.mean((y_true - y_pred) ** 2)) + diff --git a/ML/README.md b/ML/README.md index fdc8214..4e85be8 100644 --- a/ML/README.md +++ b/ML/README.md @@ -19,9 +19,10 @@ | S.No | Algorithm | S.No. | Algorithm | S.No. | Algorithm | |-------|-----------|-------|-----------|-------|-----------| -| 1 | [Mean Squared Error](./Algorithms/Losses/MeanSquaredError) | 2 | [R2 Squared](./Algorithms/Losses/R2Squared) | 3 | [Cross Entropy Loss](./Algorithms/Losses/CrossEntropyLoss) | -| 4 | [Hinge Loss](./Algorithms/Losses/HingeLoss) | 5 | [Kullback Leibler (KL) Divergence Loss](./Algorithms/Losses/KullbackLeiblerDivergenceLoss) | 6 | | -| 7 | | 8 | | 9 | | +| 1 | [Mean Squared Error](./Algorithms/Losses/MeanSquaredError) | 2 | [R2 Squared](./Algorithms/Losses/R2Squared) | 3 | [Cross Entropy Loss](./Algorithms/Losses/CrossEntropyLoss) | +| 4 | [Hinge Loss](./Algorithms/Losses/HingeLoss) | 5 | [Kullback Leibler (KL) Divergence Loss](./Algorithms/Losses/KullbackLeiblerDivergenceLoss) | 6 | [Mean Absolute Error](./Algorithms/Losses/MeanAbsoluteError) | +| 7 | [Root Mean Squared Error](./Algorithms/Losses/RootMeanSquaredError) | 8 | | 9 | | + ## Available Documentations