How to calculate RMSE using IPython / NumPy?

I'm having trouble trying to calculate the mean square error in IPython using NumPy. I am sure that the function is correct, but when I try to enter values, it gives me the following TypeError message:

TypeError: unsupported operand type(s) for -: 'tuple' and 'tuple' 

Here is my code:

 import numpy as np def rmse(predictions, targets): return np.sqrt(((predictions - targets) ** 2).mean()) print rmse((2,2,3),(0,2,6)) 

Obviously, something is wrong with my inputs. Do I need to install an array before I put it in the rmse(): string?

+6
source share
2 answers

It says that subtraction is not defined for tuples.

Try

 print rmse(np.array([2,2,3]), np.array([0,2,6])) 

instead.

+6
source

In rmse function try:

 return np.sqrt(np.mean((predictions-targets)**2)) 
+4
source

All Articles