Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate RMSE using IPython/NumPy?

I'm having issues trying to calculate root mean squared error in IPython using NumPy. I'm pretty sure the function is right, but when I try and input values, it gives me the following TypeError message:

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

Here's 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 establish the array before I put it in the rmse(): line?

like image 884
geo_coder Avatar asked Feb 21 '14 05:02

geo_coder


1 Answers

In the rmse function, try:

return np.sqrt(np.mean((predictions-targets)**2))
like image 63
lightpen Avatar answered Sep 28 '22 04:09

lightpen