简体   繁体   English

如何解决从 Statsmodels 运行 ARIMA 时出现的 ValueError?

[英]How do I solve the ValueError that occurs when I run ARIMA from Statsmodels?

I use the following code when building ARIMA我在构建 ARIMA 时使用以下代码

arima = ARIMA(ts.astype(float), freq = 'M',order=(4, d, 3)).fit()

I get the following error when I run the above:运行上面的命令时出现以下错误:

ValueError: The given frequency argument could not be matched to the given index.

My data frame looks like this:我的数据框如下所示:

Date        A          B           C        D       E           F
2020-04-01  118     10932.54    203.617     1   0.296610    0.382666
2020-05-01  144     11645.20    167.575     1   0.361111    0.401953
2020-06-01  89      8545.86     196.084     1   0.449438    0.524768
2020-07-01  117     10512.30    194.442     1   0.384615    0.472443
2020-08-01  75      6613.11     189.289     1   0.280000    0.332995

The Date column is my index. Date列是我的索引。 It does not have a frequency label.它没有频率 label。

I tried to give it a frequency label with the following我试着给它一个频率 label 与以下

df.asfreq('M')

However, this turned the values in every column, except the Date column, to NaN .但是,这会将除Date列之外的每一列中的值都变为NaN

I tried to run the ARIMA model without a frequency argument;我尝试在没有频率参数的情况下运行 ARIMA model; however, I received the following warning message:但是,我收到以下警告消息:

ValueWarning: No frequency information was provided, so inferred frequency MS will be used.

As well, I received this warning:同样,我收到了这个警告:

ValueError: The computed initial MA coefficients are not invertible
You should induce invertibility, choose a different model order, or you can pass your own start_params.

I'm not sure what to do here.我不确定在这里做什么。 Any help would be greatly appreciated.任何帮助将不胜感激。

First, you can use首先,你可以使用

df = df.resample("M").last()

to get a clean month-end df without introducing NaN values.在不引入NaN值的情况下获得干净的月末df

Second, you should be using either SARIMAX or statsmodels.tsa.arima.model.ARIMA rather than statsmodels.tsa.arima_model.ARIMA (Note the _ in the latter is a . in the former).其次,您应该使用SARIMAXstatsmodels.tsa.arima.model.ARIMA而不是statsmodels.tsa.arima_model.ARIMA (注意后者中的_是前者中的. )。 statsmodels.tsa.arima.model.ARIMA is essentially a special case of SARIMAX that generally performs better. statsmodels.tsa.arima.model.ARIMA本质上是SARIMAX的特例,通常表现更好。 You will need statsmodels 0.12.0rc0 or a build of the master branch to use the new ARIMA .您将需要 statsmodels 0.12.0rc0 或 master 分支的构建才能使用新的ARIMA

In this new model, you will not have the issues with MA invertibility.在这个新的 model 中,您不会遇到 MA 可逆性的问题。

'MS' means 'Month-Start' whereas 'M' is for 'Month-End'. “MS”表示“月开始”,而“M”表示“月结束”。

My data is for the beginning of each month, so I am supposed to pass 'MS' into the frequency argument.我的数据是每个月初的数据,所以我应该将“MS”传递给频率参数。

I solve the not invertible error with a try/except.我用 try/except 解决了不可逆错误。

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

相关问题 如何重现 statsmodels ARIMA 过滤器? - How can I reproduce the statsmodels ARIMA filter? 运行 Prophet()、ds 和 y 时如何解决 ValueError - how do i solve ValueError when running Prophet(), ds and y 使用Python训练Arima模型时如何解决LinAlgError和ValueError - how to solve LinAlgError & ValueError when training arima model with Python 错误:ValueError:仅当我尝试使用statsmodels进行散点图时,才必须将布尔值传递给DataFrame - ERROR: ValueError: Must pass DataFrame with boolean values only when I try to do a scatter plot using statsmodels 我该如何解决 ValueError? - how could i solve ValueError? 安装pyautogui时如何解决此valueerror? - How do I solve this valueerror while installing pyautogui? 如何解决这个混淆了我的代码的 ValueError 消息? - How do I Solve this ValueError message that is messing up with my code? 如何使用 Tensorflow 和 Keras 解决 ValueError 问题 - How do I solve the issue of ValueError with Tensorflow and Keras 当我求解方程组时发生TypeError - TypeError occurs when I solve this system of equations 为什么我在进行预测时从 ARIMA 模型得到几乎相同的结果? - Why do I get nearly the same results from an ARIMA model when I do the forecast?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM