Skip to content

Commit 4c95fa7

Browse files
author
TASMAYU
committed
Rewrite some comments to explain each step
1 parent 3e255e2 commit 4c95fa7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

machine_learning/loss_functions.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -672,22 +672,20 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float
672672
def root_mean_squared_error(y_true: np.ndarray, y_pred: np.ndarray) -> float:
673673
"""
674674
Calculate the Root Mean Squared Error (RMSE) between ground truth and predicted values.
675-
# ... docstring continues ...
676675
"""
677-
# LINE 1: Check if input arrays have same length
676+
# Checking if input arrays have same length
678677
if len(y_true) != len(y_pred):
679678
raise ValueError("Input arrays must have the same length.")
680679

681-
# LINE 2: Calculate squared differences between true and predicted values
680+
# Calculating squared differences between true and predicted values
682681
# (y_true - y_pred) gives errors, then we square each error
683682
squared_errors = (y_true - y_pred) ** 2
684683

685-
# LINE 3: Calculate mean of all squared errors
686-
# This gives Mean Squared Error (MSE)
684+
# Calculate mean of all squared errors
685+
# So that to get the MSE
687686
mean_squared_error = np.mean(squared_errors)
688687

689-
# LINE 4: Take square root of MSE to get RMSE
690-
# This brings units back to original scale
688+
# Taken the square root of MSE to get RMSE
691689
return np.sqrt(mean_squared_error)
692690

693691

0 commit comments

Comments
 (0)