使用单列作为输入数据预测未来数据

发布于 2025-01-22 03:27:43 字数 941 浏览 0 评论 0原文

我的输入集预测未来值时遇到麻烦。我对StatsModels是相当新的,因此我不确定是否可以使用这些大量输入数据。

这是我正在使用的数据框架。 (注意:从索引5开始,因为我必须过滤一些数据)

    year  suicides_no
5   1990       193361
6   1991       198020
7   1992       211473
8   1993       221565
9   1994       232063
10  1995       243544
11  1996       246725
12  1997       240745
13  1998       249591
14  1999       256119
15  2000       255832
16  2001       250652
17  2002       256095
18  2003       256079
19  2004       240861
20  2005       234375
21  2006       233361
22  2007       233408
23  2008       235447
24  2009       243487
25  2010       238702
26  2011       236484
27  2012       230160
28  2013       223199
29  2014       222984
30  2015       203640

“”

从中,ID喜欢获得多年来的预测(2016-2022),并将其绘制到像这样的图表。

I am having trouble with predicting future values with my input set. I am fairly new with statsmodels so I am not sure if it is even possible to do with this much input data.

This is the DataFrame that I am using. (Note: Starts at index 5 since I had to filter some data)

    year  suicides_no
5   1990       193361
6   1991       198020
7   1992       211473
8   1993       221565
9   1994       232063
10  1995       243544
11  1996       246725
12  1997       240745
13  1998       249591
14  1999       256119
15  2000       255832
16  2001       250652
17  2002       256095
18  2003       256079
19  2004       240861
20  2005       234375
21  2006       233361
22  2007       233408
23  2008       235447
24  2009       243487
25  2010       238702
26  2011       236484
27  2012       230160
28  2013       223199
29  2014       222984
30  2015       203640

From this, id like to get a prediction for the years (2016-2022) and plot it to a graph like this one.

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

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

发布评论

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

评论(1

与君绝 2025-01-29 03:27:43

这是一个相当开放的问题。我当然可以向您展示如何编写一些代码来做出 预测,但是我认为讨论如何做出预测超出了stackoverflow的范围。这将非常取决于对问题领域的良好理解。

但是,除了警告之外,演出。您建议您想查看一个StatsModel示例。

statsModels肯定能够使用这些预测。有很多方法您可以使用1D时间序列并使用它来做出未来的预测。

在这里也有一个详细的状态模型是一种常见的方法,或者是一种方法。不同的状态空间模型将取决于您是否感觉到季节性(环状行为),还是某些外源变量(行为上下文驱动因素)很重要。

我从那里调整了一个简单的示例:

import pandas as pd
import statsmodels as sm

# df = your DataFrame

endog = df.suicides_number
endog.index = pd.period_range("1990", "2015", freq="Y") 

# Construct the (very simple) AR model
mod = sm.tsa.SARIMAX(endog, order=(1, 0, 0), trend='c')

# Estimate the parameters
res = mod.fit()

res.forecast(steps=7)

order参数准确确定您获得的模型。这很简单,是一种自动化模型,着眼于过去的行为,最近的行为并向前推断。

正如我说的那样,我不能保证它会给您一个很好的预测(绝对可以将25个样本前进以预测下一个7),但是您可以测试不同的参数并阅读此类型的模型。

This is a rather open-ended problem. I can certainly show you how you might write some code to make a prediction, but I think discussing how to make a good prediction is beyond the scope of StackOverflow. It will be very dependent on a good understanding of the problem domain.

But with that caveat aside, on with the show. You've suggested you'd like to see a Statsmodel example.

Statsmodels is certainly capable of these sorts of forecasts. There are lots of approaches but yes, you can take a 1D time-series and use it to make future predictions.

There's also a detailed tutorial of state space models here - this is a common approach, or rather, family of approaches. Different state-space models would be used depending on e.g. whether you feel seasonality (cyclic behaviour), or certain exogenous variables (contextual drivers of behaviour) are important or not.

I adapted a simple example from there:

import pandas as pd
import statsmodels as sm

# df = your DataFrame

endog = df.suicides_number
endog.index = pd.period_range("1990", "2015", freq="Y") 

# Construct the (very simple) AR model
mod = sm.tsa.SARIMAX(endog, order=(1, 0, 0), trend='c')

# Estimate the parameters
res = mod.fit()

res.forecast(steps=7)

The order parameter determines exactly what sort of model you get. This is pretty simple, an autoregression model that looks at past behaviour, recent behaviour, and extrapolates forward.

As I said, I cannot guarantee it will give you a good forecast here (it's definitely a reach to take 25 samples forward to predict the next 7), but you could test different parameters and read up on this type of model.

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