From 9a768019538da34e0b0ddc13747512812a55e239 Mon Sep 17 00:00:00 2001 From: Addyk-24 Date: Thu, 9 Oct 2025 22:49:02 +0530 Subject: [PATCH 1/4] 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/4] 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/4] 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 0072c4cc097aad8a460929e9ad5078e06b6c8de8 Mon Sep 17 00:00:00 2001 From: Addyk-24 Date: Thu, 9 Oct 2025 23:19:52 +0530 Subject: [PATCH 4/4] Adding RMSE - Root Mean Squared Error Loss function for ML Evaluation --- machine_learning/loss_functions.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/machine_learning/loss_functions.py b/machine_learning/loss_functions.py index db33a5e8a22e..ed819c91a98c 100644 --- a/machine_learning/loss_functions.py +++ b/machine_learning/loss_functions.py @@ -665,28 +665,28 @@ 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. - 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) + 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)