I've two functions:
f(x) = sin(x)
and
g(x) = x - 1/6x^3
I have range(0, 2*PI)
and I want to calculate RMSE
of these two functions. How can I do this?
I've two functions:
f(x) = sin(x)
and
g(x) = x - 1/6x^3
I have range(0, 2*PI)
and I want to calculate RMSE
of these two functions. How can I do this?
Clarification of RMSE can be found here:
Root mean square error in python
In there it shows you how to calculate RMSE from two lists (or numpy arrays). You need to specify what you want your target and predicted values to be.
Below is the suggested code to calculate two lists, each populated with the results of the two functions for values between 0 and 2*PI, in increments of 0.1 (note pure python range function doesn't support the float type).
import numpy as np
def func1(x):
return np.sin(x)
def func2(x):
return x - (1/6)*(x**3)
l1 = []
l2 = []
for i in np.arange(0,2*np.pi,0.1):
l1.append(func1(i))
l2.append(func2(i))
Say you specify a new prediction list (l3) below, which takes values of 0 to 6.2 in increments of 0.1, the RMSE value that compares l3 to l1 (l3 to l2) respectively is:
# Create new list of equal length for your predictions
l3 = np.arange(0,2*np.pi,0.1)
def rmse(predictions, targets):
return np.sqrt(((predictions - targets) ** 2).mean())
print(rmse(l3,l1))
print(rmse(l3,l2))