训练ARIMA预测趋势

2024-04-26 11:59:12 发布

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

我试图用ARIMA预测一个趋势。不幸的是,我得到的输出与预期的结果相差甚远(训练和测试数据的行为非常相似),并且表明好像整个训练数据集。。。没用

df = pd.read_csv('data.csv')
df.index = pd.DatetimeIndex(df.index).to_period('D')

#data from 1/1/2016 to 31/12/2018
train = df.loc[:'2018-12-31']
test = df.loc['2019-01-01':]

model = auto_arima(train, start_p=1, start_q=1,
                   max_p=3, max_q=3, m=7,
                   start_P=0, seasonal=True,
                   d=1, D=1, trace=True,
                   error_action='ignore',
                   suppress_warnings=True,
                   stepwise=True)

model.aic()
model.fit(train)
ffforecast = model.predict(n_periods=len(test))
ffforecast = pd.DataFrame(fforecast,
                               index=test.index,
                               columns=['prediction'])
pd.concat([test, fforecast], axis=1).plot()
pyplot.show()

enter image description here

完整代码:https://pastebin.com/huer62cM

csv:https://filebin.net/rlvm3hrjetlovd64/newbikes6years.csv?t=nt3slw3y


Tags: csvtotesttruedfdataindexmodel
1条回答
网友
1楼 · 发布于 2024-04-26 11:59:12

您的模型使用了一组错误的参数。看起来您从不同的数据集中复制/粘贴了一个示例,但它不适合您

我想提出如下建议:

model = auto_arima(train, error_action='ignore', trace=True, suppress_warnings=True,seasonal=True, maxiter=10, m=7)

基于此输出,您可以在阅读参数并了解它们的功能后返回并细化参数

相关问题 更多 >