简体   繁体   中英

How to extract coefficient matrices from statsmodels.tsa.api

https://www.statsmodels.org/dev/vector_ar.html

The VAR from statsmodels allows you to fit vector autoregression model for a given time series. Vector auto regression is:

Y_t  = A_1Y_{t-1} + A_2Y_{t-2} + ... + E_t

where Y_t is a vector, A_i are coefficient matrices, E_t is residual vector. I am having difficulties extracting A_i matrices from the model.

from statsmodels.tsa.api import VAR
import numpy as np
timeseries = np.random.standard_normal([1000,10])
model = VAR(timeseries)
model_fit = model.fit(3)
model_fit.summary()

The problem is that summary() gives the effect of each variable on another one by one. is it possible to extract coefficients in a matrix form?

I have 100 variables and lag of order 3. Extracting coefficients manually will be time consuming. I cant believe that such popular package doesnt allow to write something like model_fit.coef_[1] and get the 100*100 matrix for lag of order 1.

Is there any way to do this?

Not sure exactly where but you could try something like

summary_object = model_fit.summary()

then look in summary_object.model._cache this is a big dictionary that contains a lot of values. Not sure if this is where the data you want resides, but you could find it by doing what I did and inspect using pycharm debugger/ console.

在此处输入图像描述

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM