Implement the **Root Mean Squared Error (RMSE)** metric.
Formula:
RMSE = sqrt( (1/n) * sum((y_true - y_pred)^2) )
= sqrt(MSE)
Write a function rmse(y_true, y_pred) that takes two arrays and returns the RMSE value.
Example:
y_true = [3, 5, 2, 7]
y_pred = [2.5, 5.5, 2, 8]
MSE = (0.25 + 0.25 + 0 + 1) / 4 = 0.375
RMSE = sqrt(0.375) = 0.6124 (approx)
**Explanation:** RMSE is the square root of MSE. It has the advantage of being in the same units as the target variable, making it more interpretable than MSE.
Constraints:
Test Cases
Test Case 1
Input:
y_true=[3,5,2,7], y_pred=[2.5,5.5,2,8]Expected:
0.6123724356957945Test Case 2
Input:
y_true=[1,2,3], y_pred=[1,2,3]Expected:
0.0Test Case 3
Input:
y_true=[0,0,0], y_pred=[1,1,1]Expected:
1.0+ 2 hidden test cases