Reputation: 59
Is there a test in python which allows to know if a time series is linear or not? I want to know which module of kalman filter I have to use in order to correct my forecast data.
Upvotes: 2
Views: 3224
Reputation: 317
You may want to look at statsmodels.tsa and try an ARMA (auto regressive moving average) model. Specifically the kalman filter methods can be found here.
Upvotes: 0
Reputation: 1625
You'll want to do a "linear regression". Numpy and SciPy are Python math libraries that can help.
Here's an example of a linear regression using Numpy and SciPy:
from numpy import arange
from pylab import plot,show
from scipy import stats
xi = arange(0,9)
# linearly generated sequence
y = [19, 20, 20.5, 21.5, 22, 23, 23, 25.5, 24]
slope, intercept, r_value, p_value, std_err = stats.linregress(xi,y)
print 'r-value', r_value
print 'p-value', p_value
print 'standard deviation', std_err
line = slope*xi + intercept
plot(xi,line,'r-',xi,y,'o')
show()
The closer your r-value
is to 1, the more closely your data matches then calculated line. Since the linear regression produces a line, and the r-value
tell you how your data fits the line, an r-value
of 1 would mean your series is completely linear.
Upvotes: 3