如何使用 ARIMA 预测数据?

发布于 2025-01-17 06:23:45 字数 1041 浏览 7 评论 0原文

我想使用 ARIMA 模型(自回归移动平均线)预测股票价格,并希望根据实际数据和训练数据绘制预测数据。我正在关注本教程,并且也浏览了其他教程。但它们都遵循相同的代码。以下是他们的教程链接供您参考:(https://www.analyticsvidhya.com/blog/2021/07/stock-market-forecasting-using-time-series-analysis-with-arima-model/

# Forecast
fc, se, conf= fitted.forecast(216, alpha=0.05)  # 95% conf

我期待一个图表看起来像这样在此处输入图像描述

相反,会显示一条错误消息:ValueError:值太多到解压(预期 3)

请帮忙:')

编辑:我之前尝试这样做,但它在下一个代码中产生了一条错误消息。我的下一行代码如下:

result = fitted.forecast(216, alpha =0.05)`

# Make as pandas series
fc_series = pd.Series(result, index=test_data.index)
lower_series = pd.Series(result[:, 0], index=test_data.index)
upper_series = pd.Series(result[:, 1], index=test_data.index)

错误消息:KeyError: 'key of type tuple not find and not a MultiIndex'

I wanted to forecast stock prices using the ARIMA model (Autoregressive Moving Average) and wanted to plot the forecasted data over the actual and training data. I'm following this tutorial and have browsed others too. But they all follow the same code. Here is the link to their tutorial for your reference:(https://www.analyticsvidhya.com/blog/2021/07/stock-market-forecasting-using-time-series-analysis-with-arima-model/)

# Forecast
fc, se, conf= fitted.forecast(216, alpha=0.05)  # 95% conf

I was expecting a graph that looks like thisenter image description here

Instead, an error message shows up: ValueError: too many values to unpack (expected 3)

please help :')

Edit: I tried doing that before and it produces an error message in the next code. My next line of codes are as the following:

result = fitted.forecast(216, alpha =0.05)`

# Make as pandas series
fc_series = pd.Series(result, index=test_data.index)
lower_series = pd.Series(result[:, 0], index=test_data.index)
upper_series = pd.Series(result[:, 1], index=test_data.index)

The error message: KeyError: 'key of type tuple not found and not a MultiIndex'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぃ弥猫深巷。 2025-01-24 06:23:45

看起来,预测函数不再返回三个返回值。如果您使用的版本与教程中的版本不同,则可能会发生这种情况。

请尝试以下操作:

结果=fitting.forecast(216, alpha=0.05)

然后检查结果是否包含您需要的所有数据。

It seems, that the forecast function is not returning three return values anymore. This may happen if you don’t use the same version as in the tutorial.

Please try something like:

result = fitted.forecast(216, alpha=0.05)

And then inspect the result if it does contain all the data you need.

你的他你的她 2025-01-24 06:23:45

导入库

import statsmodels.api as sm

使用带有 sm.tsa 的模型,

model = sm.tsa.ARIMA(train_data, order=(1, 1, 1))  
fitted = model.fit()
print(fitted.summary())

传递参数 Summary_frame 来获取预测,下限和上限间隔

result = fitted.get_forecast(216, alpha =0.05).summary_frame()
print(result)

制作 pandas 系列,不要忘记添加值以使系列不为空。

fc_series = pd.Series(result['mean'].values, index=test_data.index)
lower_series = pd.Series(result['mean_ci_lower'].values, index=test_data.index)
upper_series = pd.Series(result['mean_ci_upper'].values, index=test_data.index)

我希望这对你有帮助。

import library

import statsmodels.api as sm

use a model with sm.tsa

model = sm.tsa.ARIMA(train_data, order=(1, 1, 1))  
fitted = model.fit()
print(fitted.summary())

pass a parameter Summary_frame to get a forecast , lower and upper interval

result = fitted.get_forecast(216, alpha =0.05).summary_frame()
print(result)

Make pandas series, dont forget add values to get series not null.

fc_series = pd.Series(result['mean'].values, index=test_data.index)
lower_series = pd.Series(result['mean_ci_lower'].values, index=test_data.index)
upper_series = pd.Series(result['mean_ci_upper'].values, index=test_data.index)

I hope this help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文