我正在做一个时间序列分析,我试图找到我的时间序列的周期性。我已经完成了以下代码并找到了图表(见附件):
# Periodicity of the two trajectories
from statsmodels import api as sm
# convert dataframe to array
np_df= np.asarray(df['Combined'], dtype=float)
# remove mean to create signal oscillating around 0
np_df= np_df- np.mean(np_df)
#get the autocorrelation coefficient
acf= sm.tsa.acf(np_df, nlags=len(np_df))
plt.figure(figsize = (10, 8))
lag = np.arange(len(np_df)) / 2. / 24.
plt.plot(lag, acf)
plt.xlim((0, 120))
plt.xlabel('Lags (days)')
plt.ylabel('Autocorrelation')
plt.figure(figsize = (10, 8))
plt.plot(lag, acf)
plt.xlim((0, 22))
plt.xlabel('Lags (days)')
plt.ylabel('Autocorrelation')
使用 fft pack 查找周期性
from scipy import fftpack
ft_df= fftpack.fft(np_df, axis=0)
freq= fftpack.fftfreq(np_df.shape[0], time[1]-time[0])
periods= 1/freq
plt.figure()
plt.plot(periods, abs(ft_df)*1e-3, 'o')
plt.xlim(0,22)
plt.xlabel('Period')
plt.ylabel('Power ($cdot10^3$)')
plt.show()
我的问题是我认为周期性,我能解释的是1,也许是2.5?我的方法和解释是否正确?
提前致谢!