在 statsmodel 中拟合新模型失败 - RuntimeError

Fit new model in statsmodel fails - RuntimeError

我使用 statsmodels 创建了一个 AR 模型。这行得通,但是当我尝试创建新模型时,我遇到了 RuntimeError :

RuntimeError: Model has been fit using maxlag=1, method=cmle, ic=None, trend=c. These cannot be changed in subsequent calls to fit. Instead, use a new instance of AR.

这是我生成第一个模型的方式:

model=AR(df['Pop'])
AR1fit=model.fit(maxlag=1)

...
AR1fit.predict(start=start,end=end)


#the 2nd model:
AR2fit=model.fit(maxlag=2)
>>>
RuntimeError: 
Model has been fit using maxlag=1, method=cmle, ic=None, trend=c. These
cannot be changed in subsequent calls to `fit`. Instead, use a new instance of
AR.

我还没有发现任何关于这个特定错误的post,我的目标是适应新模型。

您必须为 AR(2) 实例化一个新模型,然后调用 fit 方法:

model2 = AR(df['Pop'])
AR2fit = model2.fit(maxlag=2)