How to fetch the VAR model summary

383 views
Skip to first unread message

Kai Wang

unread,
May 30, 2015, 10:10:44 PM5/30/15
to pystat...@googlegroups.com
Hi,

I'm trying to build a var model, and I cannot find what I need in the document. First, you can use summary() to get all the model result at one time, what if I want to get each details? like, I want to store the AIC value in varible, or I want to shore one of the reuslt model in a array with each coef I can get?

And how to predict the test set and get accuary or other model  criterion.

Kai

josef...@gmail.com

unread,
May 30, 2015, 11:05:29 PM5/30/15
to pystatsmodels
On Sat, May 30, 2015 at 9:57 PM, Kai Wang <kaiwang...@gmail.com> wrote:
Hi,

I'm trying to build a var model, and I cannot find what I need in the document. First, you can use summary() to get all the model result at one time, what if I want to get each details? like, I want to store the AIC value in varible, or I want to shore one of the reuslt model in a array with each coef I can get?

all those things should be attached as attributes to or calculated by methods of the results instance returned by `fit`

some of them are missing a docstring or explanation
 

And how to predict the test set and get accuary or other model  criterion.

there is a `forecast` method, but I'm not familiar with the details.

In most cases we currently only calculate insample (training data) goodness of fit measures.

Josef

 

Kai

Kai Wang

unread,
May 31, 2015, 2:13:27 AM5/31/15
to pystat...@googlegroups.com
Thanks. There is a predict method in VAR, is described here: 

But I don't understand what should be feed into the function as "params".

error message: 

>>> model.predict(2015,2016)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/Library/Python/2.7/site-packages/statsmodels-0.6.1-py2.7-macosx-10.10-intel.egg/statsmodels/tsa/vector_ar/var_model.py", line 347, in predict

    start = self._get_predict_start(start, lags)

  File "/Library/Python/2.7/site-packages/statsmodels-0.6.1-py2.7-macosx-10.10-intel.egg/statsmodels/tsa/vector_ar/var_model.py", line 341, in _get_predict_start

    return super(VAR, self)._get_predict_start(start)

  File "/Library/Python/2.7/site-packages/statsmodels-0.6.1-py2.7-macosx-10.10-intel.egg/statsmodels/tsa/base/tsa_model.py", line 131, in _get_predict_start

    self._set_predict_start_date(start)

  File "/Library/Python/2.7/site-packages/statsmodels-0.6.1-py2.7-macosx-10.10-intel.egg/statsmodels/tsa/base/tsa_model.py", line 103, in _set_predict_start_date

    raise ValueError("Start must be <= len(endog)")

ValueError: Start must be <= len(endog)

>>> model.predict()

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: predict() takes at least 2 arguments (1 given)

josef...@gmail.com

unread,
May 31, 2015, 8:37:33 AM5/31/15
to pystatsmodels
On Sun, May 31, 2015 at 2:13 AM, Kai Wang <kaiwang...@gmail.com> wrote:
Thanks. There is a predict method in VAR, is described here: 

But I don't understand what should be feed into the function as "params".


A model doesn't know or store what the estimated parameters are. So predict method in a model usually require the `results.params` as argument.

However, the results instance that is returned by `fit` should have the method that automatically uses the estimated parameters.

There doesn't seem to be a predict method in the results, but there is the n-step ahead forecast function


I'm not really familiar with the details there, and can only try to figure out from the source and examples.

Josef

Kai Wang

unread,
Jun 2, 2015, 1:08:29 AM6/2/15
to pystat...@googlegroups.com
I think I figured out the usage of   forecast function, The code is like:

            model = VAR(trainframe)
    
            order_sel = model.select_order()
            aicBest = order_sel['aic']
            result = model.fit(aicBest)
            predictTest = result.forecast(trainframe.values[-aicBest:],10)

It will predict 10 future time point.

在 2015年5月31日星期日 UTC+8下午8:37:33,josefpktd写道:
Reply all
Reply to author
Forward
0 new messages