Skip to content
Closed
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
34 changes: 34 additions & 0 deletions machine_learning/loss_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,40 @@
return np.sum(kl_loss)


def root_mean_squared_error(y_true, y_pred):
"""
Root Mean Squared Error (RMSE)

Check failure on line 669 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:669:1: W293 Blank line contains whitespace
Root Mean Squared Error (RMSE) is a standard metric used to evaluate
the accuracy of regression models.

Check failure on line 672 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:672:1: W293 Blank line contains whitespace
It measures the average magnitude of the prediction errors, giving
higher weight to larger errors due to squaring.

Check failure on line 675 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:675:1: W293 Blank line contains whitespace
RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2)

Check failure on line 677 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:677:1: W293 Blank line contains whitespace
Reference: https://en.wikipedia.org/wiki/Root_mean_square_deviation

Check failure on line 679 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:679:1: W293 Blank line contains whitespace
Parameters:
y_pred: Predicted Value
y_true: Actual Value

Check failure on line 683 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:683:1: W293 Blank line contains whitespace
Returns:
float: The RMSE Loss function between y_pred and y_true

Check failure on line 686 in machine_learning/loss_functions.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

machine_learning/loss_functions.py:686:1: W293 Blank line contains whitespace
Example:
>>> y_true = np.array([100, 200, 300])
>>> y_pred = np.array([110, 190, 310])
>>> rmse(y_true, y_pred)
3.42
"""
y_true, y_pred = np.array(y_true), np.array(y_pred)

rmse = np.sqrt(np.mean((y_pred - y_true) ** 2))

return rmse


if __name__ == "__main__":
import doctest

Expand Down
Loading