我试图在数据集上运行滚动回归。但我收到一个错误代码,说明“endog需要有ndim 1,但有ndim 2”
据我所知(python新手),给定(1763,)的y.shape,维度是1
我曾尝试使用.ravel()和reforme()使其更加一维(尽管它已经是一维的),但仍然得到相同的错误代码
以下是导致错误的代码:
# Start trialing local linear regression
dataset = df.values
X = dataset[:-1,1:]
y = dataset[:-1, 0].flatten()
y.shape, X.shape
输出:((1763,),(1763,3))
rols = RollingOLS(X, y, window=60)
rres = rols.fit()
params = rres.params
print(params.head())
print(params.tail())
错误代码:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-20-7ca687ee0af3> in <module>
14 import pandas as pd
15
---> 16 rols = RollingOLS(X, y, window=60)
17 rres = rols.fit()
18 params = rres.params
/opt/conda/lib/python3.8/site-packages/statsmodels/regression/rolling.py in __init__(self, endog, exog, window, min_nobs, missing, expanding)
445 expanding=False
446 ):
--> 447 super().__init__(
448 endog,
449 exog,
/opt/conda/lib/python3.8/site-packages/statsmodels/regression/rolling.py in __init__(self, endog, exog, window, weights, min_nobs, missing, expanding)
154 self.k_constant = k_const
155 self.data.const_idx = const_idx
--> 156 self._y = array_like(endog, "endog")
157 nobs = self._y.shape[0]
158 self._x = array_like(exog, "endog", ndim=2, shape=(nobs, None))
/opt/conda/lib/python3.8/site-packages/statsmodels/tools/validation/validation.py in array_like(obj, name, dtype, ndim, maxdim, shape, order, contiguous, optional)
145 if arr.ndim != ndim:
146 msg = "{0} is required to have ndim {1} but has ndim {2}"
--> 147 raise ValueError(msg.format(name, ndim, arr.ndim))
148 if shape is not None:
149 for actual, req in zip(arr.shape, shape):
ValueError: endog is required to have ndim 1 but has ndim 2
Y是endog,X是exog,您需要显式地切换或命名参数
相关问题 更多 >
编程相关推荐