Traceback (most recent call last): File "D:\kelly\PycharmProjects\pythonProject8\大作业.py", line 145, in <module> model = smf.ols('ExRet ~ PEL1', data=datafit[['ExRet', 'PEL1']].iloc[:(n_in+i),:]) File "D:\python3.10\lib\site-packages\statsmodels\base\model.py", line 226, in from_formula mod = cls(endog, exog, *args, **kwargs) File "D:\python3.10\lib\site-packages\statsmodels\regression\linear_model.py", line 906, in __init__ super(OLS, self).__init__(endog, exog, missing=missing, File "D:\python3.10\lib\site-packages\statsmodels\regression\linear_model.py", line 733, in __init__ super(WLS, self).__init__(endog, exog, missing=missing, File "D:\python3.10\lib\site-packages\statsmodels\regression\linear_model.py", line 190, in __init__ super(RegressionModel, self).__init__(endog, exog, **kwargs) File "D:\python3.10\lib\site-packages\statsmodels\base\model.py", line 267, in __init__ super().__init__(endog, exog, **kwargs) File "D:\python3.10\lib\site-packages\statsmodels\base\model.py", line 92, in __init__ self.data = self._handle_data(endog, exog, missing, hasconst, File "D:\python3.10\lib\site-packages\statsmodels\base\model.py", line 132, in _handle_data data = handle_data(endog, exog, missing, hasconst, **kwargs) File "D:\python3.10\lib\site-packages\statsmodels\base\data.py", line 700, in handle_data return klass(endog, exog=exog, missing=missing, hasconst=hasconst, File "D:\python3.10\lib\site-packages\statsmodels\base\data.py", line 88, in __init__ self._handle_constant(hasconst) File "D:\python3.10\lib\site-packages\statsmodels\base\data.py", line 132, in _handle_constant exog_max = np.max(self.exog, axis=0) File "<__array_function__ internals>", line 180, in amax File "D:\python3.10\lib\site-packages\numpy\core\fromnumeric.py", line 2793, in amax return _wrapreduction(a, np.maximum, 'max', axis, None, out, File "D:\python3.10\lib\site-packages\numpy\core\fromnumeric.py", line 86, in _wrapreduction return ufunc.reduce(obj, axis, dtype, out, **passkwargs) ValueError: zero-size array to reduction operation maximum which has no identity报错如何四u该
时间: 2023-07-21 11:53:22 浏览: 143
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
根据报错信息,很可能是因为数据集中的某些列中没有数据,导致使用`np.max()`函数时出现了"zero-size array"的错误。可以在使用`np.max()`函数之前先检查数据集中是否存在空值或缺失值,或者可以使用`np.nanmax()`函数来处理数据,该函数可以忽略缺失值并返回最大值。同时,也可以检查一下数据的维度是否符合要求。如果无法解决问题,可以将报错信息和相关代码提供给更有经验的人士进行调试。
阅读全文