我正在尝试使用statsmodels
库运行VAR,显然我的endog格式是错误的。尝试了一些不同的东西,但我找不到如何解决它。
我正在运行以下代码:
def VAR_run(pred_frame,targetframe):
#preparing the dates
dates=pred_frame.index
# preparing target
targetmatrix=targetframe.as_matrix()
# preparing pred_frame
predmatrix=pred_frame.as_matrix()
#creating endog
timeseries=(predmatrix,targetmatrix)
model=VAR((timeseries),dates=dates)
我得到的错误如下:
File "/Users/file.py", line 1198, in M_pred_frame
VAR_run(pred_frame,targetframe)
File "/file.py", line 1156, in VAR_run
model=VAR((timeseries),dates=dates)
File "/Library/Python/2.7/site-packages/statsmodels/tsa/vector_ar/var_model.py", line 334, in __init__
raise ValueError("Only gave one variable to VAR")
ValueError: Only gave one variable to VAR
任何人都可以启发我的旅程吗?
额外信息
pred_frame
原本是像这样的大熊猫DataFrame
:
Value lag1 2lag 3lag 4lag 5lag 6lag 7lag 8lag 9lag
Date
...
2015-12-01 1.01 0.82 0.54 0.22 0.62 0.79 0.74 0.71 1.32 1.22
2016-01-01 0.96 1.01 0.82 0.54 0.22 0.62 0.79 0.74 0.71 1.32
2016-02-01 1.27 0.96 1.01 0.82 0.54 0.22 0.62 0.79 0.74 0.71
targetframe
最初也是像这样的大熊猫DataFrame
:
Tgt
Date
...
2015-10-01 0.54
2015-11-01 0.82
2015-12-01 1.01
2016-01-01 0.96
2016-02-01 1.27
当变成数组时,它们看起来像这样:
targetmatrix = [[ nan]
[ 1.18]
[ 0.5 ]
[ 0.51]
...]
predmatrix= ...[ 1.27 0.96 1.01 ..., -2.14865885 -2.14865885
-3.19355784]
[ nan nan nan ..., -18.13211803 -2.14865885
-2.14865885]
[ nan nan nan ..., nan nan
nan]]
dates = DatetimeIndex(['1958-04-01', '1958-05-01', '1958-06-01', '1958-07-01',
'1958-08-01', '1958-09-01', '1958-10-01', '1958-11-01',
'1958-12-01', '1959-01-01',
...
'2015-07-01', '2015-08-01', '2015-09-01', '2015-10-01',
'2015-11-01', '2015-12-01', '2016-01-01', '2016-02-01',
'2016-03-01', '2016-04-01'],
dtype='datetime64[ns]', name=u'Date', length=697, freq='MS')
关于形状:
targetmatrix.shape = (230, 1)
predmatrix.shape = (697, 1920)
dates.shape=(697,)
我们将非常感谢您的帮助:)