Expert Answer
Anonymous
let's consider two vectors y and y_bis, the root mean square error between these two vectors is equal to the L2-norm between y and y_bis. in another words, let's consider z = y - y_bis. the root mean squared error corresponds to the square root of the sum square element of z.
I will code it in Python :
first thing to have in mind is to code the sqrt function to compute square root of a number. for this purpose we use newton method.
def sqrt(x: float, epsilon: float = 1e-10) -> float:
if x < 0:
raise ValueError("Cannot compute square root of negative number.")
if x == 0 or x == 1:
return x
guess = x / 2.0
while abs(guess * guess - x) > epsilon:
guess = (guess + x / guess) / 2.0
return guess
now that we have the sqrt function we can define the root mean squared error function as :
def rmse(y: List[float], y_bis:List[float]) -> float:
return sqrt(sum((y-y_bis)**2))
sum() is a native function in python.