我已经开始学习状态模型包,不能用arima实现基本的预测。
错误是
ValueError:给定一个熊猫对象,索引中不包含日期
我正在尝试将其作为一个版本:
df = make_df(filename_data)
y = []
x = []
# here I am preparing day by day sequence as that I have inconsistent data and I set 0 to NAN values
start_date = df[date_col].min()
end_date = df[date_col].max()
while start_date <= end_date:
x.append(start_date)
try:
y.append(
df[df[date_col] == start_date][rev_col].values[0])
except:
y.append(0)
start_date += datetime.timedelta(days=1)
y = np.array(y)
x = np.array(x)
y = pd.TimeSeries(y, index=x)
print(y)
arma_mod = sm.tsa.ARMA(y, order=(2,2))
arma_res = arma_mod.fit(trend='nc', disp=-1)在那之前我试过
df = make_df(filename_data)
y = np.array(df[rev_col])
x = np.array(df[date_col])
y = pd.TimeSeries(y, index=x)为什么会这样?
日期收入数据看起来没问题:
2014-08-04 59477
2014-08-05 29989
2014-08-06 29989
2014-08-07 116116发布于 2016-02-19 18:15:47
您可以使用DataFrame ()简单地转换您的as_matrix()。
示例工作代码:
from statsmodels.tsa.arima_model import ARIMA
import numpy as np
def plot_residuals(data, ord=(2, 0, 1)):
model = ARIMA(endog=data, order=(ord[0], 0, ord[1])).fit()
plt.plot(model.resid)
plt.show()
data = np.log(data.values) - np.log(data.values.shift()).to_frame().dropna().as_matrix()
plot_residuals(data, (2, 0, 1))由于状态模型有许多未解决的问题,它只能暂时帮助您。
https://stackoverflow.com/questions/34902066
复制相似问题