Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new loss functions #31

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ML/Algorithms/Losses/MeanAbsoluteError/MeanAbsoluteError.py
Original file line number Diff line number Diff line change
@@ -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()
16 changes: 16 additions & 0 deletions ML/Algorithms/Losses/RootMeanSquaredError/RootMeanSquaredError.py
Original file line number Diff line number Diff line change
@@ -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))

7 changes: 4 additions & 3 deletions ML/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down