我的ARIMA模型在python中给出了一条平线

2024-04-29 00:37:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为我的数据集构建一个ARIMA模型,该数据集位于一个由2015年3月23日至2019年8月17日的数据组成的pandas数据框架中。我删除了值为0或nan的行(每行代表一天),所以总共有大约1544行。我把专栏时间花在pd.日期时间把它作为索引。数据看起来像这样

                     time   emails_received
    2015-03-23 04:00:00+00:00   474483.000000
    2015-03-24 04:00:00+00:00   378195.000000

时间图是这样的 enter image description here

自相关像这样

enter image description here

在运行dbfuller测试之后,它给了我一个p值0.00005,这意味着它可能是静止的。 我创建了一个训练和测试数组,并将其放入ARIMA中。你知道吗

x = fa2.values   #fa is the name of the df that holds my dataset
train = x[0:1235] #train holds 80% of the values
test = x[1235:]   #test with the remaining 20%
predictions = []

from statsmodels.tsa.ar_model import AR
from sklearn.metrics import mean_squared_error

model = AR(train)
model_fitted = model.fit()
predictions = model_fitted.predict(start = 1234, end = 1544)
plt.plot(test)
plt.plot(predictions, color = 'red')

现在我的问题是,一旦我绘制了测试和预测,预测就会变成一条直线,这看起来显然不准确。当我在ARIMA中使用p,d,q值时,我仍然得到相同的结果。发生这种情况有什么特别的原因吗?这是情节的图片。 enter image description here


Tags: ofthe数据fromtestimportmodel时间