Rolling Regression: ValueError: endog is required to have ndim 1 but has ndim 2
Rolling Regression: ValueError: endog is required to have ndim 1 but has ndim 2
我正在尝试 运行 对数据集进行滚动回归。但是我收到一个错误代码,指出 'endog is required to have ndim 1 but has ndim 2'.
据我了解(python 的新手)维度为 1,给定 (1763,) 的 y.shape。
我尝试使用 .ravel() 和 reshape() 使其更加一维(即使它已经是一维),但我仍然收到相同的错误代码。
这是导致错误的代码:
# 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
RollingOLS(endog, exog, window=None, *, min_nobs=None, missing='drop', expanding=False)
Y 是 endog,X 是 exog,您需要显式切换或命名参数
我正在尝试 运行 对数据集进行滚动回归。但是我收到一个错误代码,指出 'endog is required to have ndim 1 but has ndim 2'.
据我了解(python 的新手)维度为 1,给定 (1763,) 的 y.shape。
我尝试使用 .ravel() 和 reshape() 使其更加一维(即使它已经是一维),但我仍然收到相同的错误代码。
这是导致错误的代码:
# 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
RollingOLS(endog, exog, window=None, *, min_nobs=None, missing='drop', expanding=False)
Y 是 endog,X 是 exog,您需要显式切换或命名参数