[英]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).其次,您应该使用
SARIMAX
或statsmodels.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.