简体   繁体   English

Python中的Statsmodels包 - 检索ARIMA模型的样本外预测的问题

[英]Statsmodels package in Python - issues with retrieving out-of-sample prediction of ARIMA model

I'm trying to retrieve an out-of-sample prediction for ARIMA model. 我正在尝试检索ARIMA模型的样本外预测。 However, I constantly receive errors and I'm not sure how should I proceed now:( The code is the following: 但是,我经常收到错误,我不知道我现在该怎么办:(代码如下:

    from statsmodels.tsa.arima_model import ARIMA
    fit = ARIMA(endog, (1,1,1)).fit()
    params = fit.params
    forecast = fit.predict(params.all(), start='2015-9-21', end='2016-9-21', typ='levels')

It worked well (ie giving me a result, but not an out-of-sample one...) when I only used 当我只使用时,它运作良好(即给我一个结果,但不是一个非样本的...)

    forecast = fit.predict(params.all(), typ='levels')

but when I added "start" and "end" dates (or only "start") it doesn't want to work, I constantly get errors. 但是当我添加“开始”和“结束”日期(或只是“开始”)它不想工作时,我经常会出错。 In case of the first cited chunk of code its: "TypeError: predict() got multiple values for keyword argument 'start'". 在第一个引用的代码块的情况下:“TypeError:predict()得到关键字参数'start'”的多个值。 I also tried with datetime type and it also didn't work. 我也尝试过datetime类型,但也没用。 Can anyone help me with it? 任何人都可以帮助我吗?

I was getting a similar error to the one reported above: 我收到与上面报告的类似的错误:

"AttributeError: 'NoneType' object has no attribute 'get_loc' "

But I realised this was because I was passing an array (or list) without a datetime index, eg if you use pandas dataframes and input it as df.values , then you drop the time index, and ARMA doesn't have the dates information (so dates is None) which triggers this error. 但我意识到这是因为我传递的数组(或列表)没有日期时间索引,例如,如果您使用pandas数据帧并将其输入为df.values ,那么您删除时间索引,并且ARMA没有日期信息(因此日期为无)会触发此错误。 I suggest you feed in a pd.DataFrame or pd.Series object with a datetime index. 我建议你pd.Series带有日期时间索引的pd.DataFramepd.Series对象。 See also this thread http://pystatsmodels.narkive.com/rhX3T509/arma-predict-throws-attributeerror-with-start-and-end-dates 另请参见此主题http://pystatsmodels.narkive.com/rhX3T509/arma-predict-throws-attributeerror-with-start-and-end-dates

You can use 您可以使用

fit.forecast(steps, exog=None, alpha=0.05)

where steps=365 according to your start and end parameter if its on monthly basis. 其中steps=365根据您的startend参数(如果是每月)。 Refer to the this answer 请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用statsmodels进行ARMA样本外预测 - ARMA out-of-sample prediction with statsmodels ARIMA在statsmodels中没有样本预测? - ARIMA out of sample prediction in statsmodels? Statsmodels OLS get_prediction 对样本外数据 - Statsmodels OLS get_prediction on out-of-sample data 返回StatsModel中样本外预测的标准和置信区间 - Return std and confidence intervals for out-of-sample prediction in StatsModels 如何在 Python 中使用 ARIMA model 预测样本外的时间序列? - How to forecast a time series out-of-sample using an ARIMA model in Python? 由statsmodel拟合的arima模型的样本外模拟 - Out-of-sample simulation of arima model fitted by statsmodel 在 Statsmodels -python 中使用 SARIMAX 预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using SARIMAX in Statsmodels -python statsmodels:使用公式可提供给result.predict()的样本外预测的允许格式是什么 - statsmodels: What are the allowable formats to give to result.predict() for out-of-sample prediction using formula statsmodels ARMA预测样本外 - statsmodels ARMA to predict out-of-sample 使用 Statsmodels -python 中的时变回归示例代码预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using Time-varying regression example code in Statsmodels -python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM