Skip to content

Commit 9a76801

Browse files
committed
Adding RMSE - Root Mean Squared Error Loss function for ML Evaluation
1 parent 788d95b commit 9a76801

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

machine_learning/loss_functions.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,32 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float
662662
kl_loss = y_true * np.log(y_true / y_pred)
663663
return np.sum(kl_loss)
664664

665+
def root_mean_squared_error(y_true, y_pred):
666+
"""
667+
Root Mean Squared Error (RMSE)
668+
669+
RMSE = sqrt( (1/n) * Σ (y_true - y_pred) ^ 2)
670+
671+
672+
Args:
673+
y_pred: Predicted Value
674+
y_true: Actual Value
675+
Returns:
676+
float: The RMSE Loss function between y_Pred and y_true
677+
678+
Example:
679+
>>> y_true = np.array([100, 200, 300])
680+
>>> y_pred = np.array([110, 190, 310])
681+
>>> rmse(A_t, F_t)
682+
3.42
683+
684+
"""
685+
y_true, y_pred = np.array(y_true), np.array(y_pred)
686+
687+
rmse = np.sqrt(np.mean((y_pred - y_true) ** 2))
688+
689+
return rmse
690+
665691

666692
if __name__ == "__main__":
667693
import doctest

0 commit comments

Comments
 (0)