python - Python StatsModels & Appelpy:MissingDataError:exog 包含 inf 或 nans
问题描述
问题
exog contains inf or nan
在使用基本上包装了 statsmodels 库的 appelpy 库时获取分类。当我检查我的数据帧的最大、最小和 nan 计数时,我得到16.515144564913754, -17.483752761281725, 0
.
关于可能出错的任何想法?
完整的堆栈跟踪
--> 587 self.train_transformed_data.columns.values,
588 ).fit()
589 return ols
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/appelpy/linear_model.py in fit(self, printing)
637 self._model_selection_stats = model_selection_dict
638
--> 639 self._standardize_results()
640
641 self._is_fitted = True
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/appelpy/linear_model.py in _standardize_results(self)
663 # Model fitting
664 model_standardized = sm.OLS(self._y_standardized,
--> 665 sm.add_constant(self._X_standardized))
666 results_obj = model_standardized.fit(cov_type=self._cov_type)
667 self._resid_standardized = pd.Series((self._results.get_influence()
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, missing, hasconst, **kwargs)
836 **kwargs):
837 super(OLS, self).__init__(endog, exog, missing=missing,
--> 838 hasconst=hasconst, **kwargs)
839 if "weights" in self._init_keys:
840 self._init_keys.remove("weights")
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, weights, missing, hasconst, **kwargs)
682 weights = weights.squeeze()
683 super(WLS, self).__init__(endog, exog, missing=missing,
--> 684 weights=weights, hasconst=hasconst, **kwargs)
685 nobs = self.exog.shape[0]
686 weights = self.weights
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, **kwargs)
194 """
195 def __init__(self, endog, exog, **kwargs):
--> 196 super(RegressionModel, self).__init__(endog, exog, **kwargs)
197 self._data_attr.extend(['pinv_wexog', 'wendog', 'wexog', 'weights'])
198
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
214
215 def __init__(self, endog, exog=None, **kwargs):
--> 216 super(LikelihoodModel, self).__init__(endog, exog, **kwargs)
217 self.initialize()
218
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
66 hasconst = kwargs.pop('hasconst', None)
67 self.data = self._handle_data(endog, exog, missing, hasconst,
---> 68 **kwargs)
69 self.k_constant = self.data.k_constant
70 self.exog = self.data.exog
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/base/model.py in _handle_data(self, endog, exog, missing, hasconst, **kwargs)
89
90 def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
---> 91 data = handle_data(endog, exog, missing, hasconst, **kwargs)
92 # kwargs arrays could have changed, easier to just attach here
93 for key in kwargs:
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/base/data.py in handle_data(endog, exog, missing, hasconst, **kwargs)
633 klass = handle_data_class_factory(endog, exog)
634 return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
--> 635 **kwargs)
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/base/data.py in __init__(self, endog, exog, missing, hasconst, **kwargs)
78 self.const_idx = None
79 self.k_constant = 0
---> 80 self._handle_constant(hasconst)
81 self._check_integrity()
82 self._cache = {}
~/.local/share/virtualenvs/crawto-LwgXxa6A/lib/python3.6/site-packages/statsmodels/base/data.py in _handle_constant(self, hasconst)
124 ptp_ = np.ptp(self.exog, axis=0)
125 if not np.isfinite(ptp_).all():
--> 126 raise MissingDataError('exog contains inf or nans')
127 const_idx = np.where(ptp_ == 0)[0].squeeze()
128 self.k_constant = const_idx.size
MissingDataError: exog contains inf or nans```
解决方案
推荐阅读
- javascript - 如何在反应项目中处理一个地方的axios错误?
- javascript - 为什么符号计算的属性名称不能在 VUE 数据中使用
- asynchronous - 发送 API 响应后使用 Response.OnCompleted 执行工作(.NET Core 3.1)
- angular - 如何从Angular中的验证器错误中获取价值
- authentication - 向具有 LDAP 身份验证的用户授予授权
- c++ - 在声明时使用 val.Class 定义类对象的数组,其中数组在构造函数初始化列表和分配有成员数组的 ptr 成员中
- java - 如何使用 HQL 将 oracle regexp_substr 转换为 PostgreSQL
- html - 如何使表格标题全宽?
- python - 使用自定义 ptransform 时使用数据流运行器构建光束管道时出现递归错误
- sed - 如何在同一行附加变量