From 9a768019538da34e0b0ddc13747512812a55e239 Mon Sep 17 00:00:00 2001 From: Addyk-24 Date: Thu, 9 Oct 2025 22:49:02 +0530 Subject: [PATCH 1/5] Adding RMSE - Root Mean Squared Error Loss function for ML Evaluation --- machine_learning/loss_functions.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index 0bd9aa8b5401..0cd44fe3da05 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -662,6 +662,32 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float kl_loss = y_true * np.log(y_true / y_pred) return np.sum(kl_loss) +def root_mean_squared_error(y_true, y_pred): + """ + Root Mean Squared Error (RMSE) + + RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2) + + + Args: + y_pred: Predicted Value + y_true: Actual Value + Returns: + float: The RMSE Loss function between y_Pred and y_true + + Example: + >>> y_true = np.array([100, 200, 300]) + >>> y_pred = np.array([110, 190, 310]) + >>> rmse(A_t, F_t) + 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 From 6e05e31c7363afec029e7ddb29fe5e51160d6bd9 Mon Sep 17 00:00:00 2001 From: Addyk-24 Date: Thu, 9 Oct 2025 22:52:36 +0530 Subject: [PATCH 2/5] Adding RMSE - Root Mean Squared Error Loss function for ML Evaluation --- machine_learning/loss_functions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index 0cd44fe3da05..04d8bfcfeb9b 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -668,7 +668,6 @@ def root_mean_squared_error(y_true, y_pred): RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2) - Args: y_pred: Predicted Value y_true: Actual Value From 9ae7622ba8d798044027c2001ed59bdc764c7511 Mon Sep 17 00:00:00 2001 From: Addyk-24 Date: Thu, 9 Oct 2025 22:59:53 +0530 Subject: [PATCH 3/5] Adding RMSE - Root Mean Squared Error Loss function for ML Evaluation --- machine_learning/loss_functions.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index 04d8bfcfeb9b..db33a5e8a22e 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -666,11 +666,18 @@ def root_mean_squared_error(y_true, y_pred): """ Root Mean Squared Error (RMSE) + Root Mean Squared Error (RMSE) is a standard metric used to evaluate the accuracy of regression models. + It measures the average magnitude of the prediction errors, giving higher weight to larger errors due to squaring. + The RMSE value is always non-negative, and a lower RMSE indicates better model performance. + RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2) - Args: + Reference: https://en.wikipedia.org/wiki/Root_mean_square_deviation + + Parameters: y_pred: Predicted Value y_true: Actual Value + Returns: float: The RMSE Loss function between y_Pred and y_true From f3f8a5792962af4f5787b7f9b63b1cf033caeedf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 17:31:31 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- machine_learning/loss_functions.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index db33a5e8a22e..3d48b3b18101 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -662,12 +662,13 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float kl_loss = y_true * np.log(y_true / y_pred) return np.sum(kl_loss) + def root_mean_squared_error(y_true, y_pred): """ Root Mean Squared Error (RMSE) - Root Mean Squared Error (RMSE) is a standard metric used to evaluate the accuracy of regression models. - It measures the average magnitude of the prediction errors, giving higher weight to larger errors due to squaring. + Root Mean Squared Error (RMSE) is a standard metric used to evaluate the accuracy of regression models. + It measures the average magnitude of the prediction errors, giving higher weight to larger errors due to squaring. The RMSE value is always non-negative, and a lower RMSE indicates better model performance. RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2) @@ -680,7 +681,7 @@ def root_mean_squared_error(y_true, y_pred): Returns: float: The RMSE Loss function between y_Pred and y_true - + Example: >>> y_true = np.array([100, 200, 300]) >>> y_pred = np.array([110, 190, 310]) From e9344dc3187a5d894a0c8a7e8b607dd0165efbbb Mon Sep 17 00:00:00 2001 From: Aditya Katkar Date: Thu, 9 Oct 2025 23:11:32 +0530 Subject: [PATCH 5/5] Update loss_functions.py --- machine_learning/loss_functions.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index 3d48b3b18101..7a34d703838f 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -666,28 +666,29 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float def root_mean_squared_error(y_true, y_pred): """ Root Mean Squared Error (RMSE) - - Root Mean Squared Error (RMSE) is a standard metric used to evaluate the accuracy of regression models. - It measures the average magnitude of the prediction errors, giving higher weight to larger errors due to squaring. - The RMSE value is always non-negative, and a lower RMSE indicates better model performance. - - RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2) - + + Root Mean Squared Error (RMSE) is a standard metric used to evaluate + the accuracy of regression models. + + It measures the average magnitude of the prediction errors, giving + higher weight to larger errors due to squaring. + + RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2) + Reference: https://en.wikipedia.org/wiki/Root_mean_square_deviation - + Parameters: y_pred: Predicted Value y_true: Actual Value - + Returns: - float: The RMSE Loss function between y_Pred and y_true - + float: The RMSE Loss function between y_pred and y_true + Example: >>> y_true = np.array([100, 200, 300]) >>> y_pred = np.array([110, 190, 310]) - >>> rmse(A_t, F_t) + >>> rmse(y_true, y_pred) 3.42 - """ y_true, y_pred = np.array(y_true), np.array(y_pred)