如何修复statsmodels.formula.api.ols中的代码

时间:2019-08-19 11:26:07

标签: python python-3.x statsmodels

我正在尝试使用以下代码在statsmodels.formula.api.ols中拟合模型。我需要在哪里修复它?

import statsmodels.formula.api as smf

data['target'] = data[selected_cell] # иначе дает ошибку в ols

m1 = smf.ols('target ~ ' + ' + '.join(feature_list), data=data)

fitted = m1.fit(cov_type='HC1')

print(fitted.summary())

我期望具有OLS回归结果的表的输出。

但是我收到以下错误日志:


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-105-661122a7ca21> in <module>()
----> 1 m1 = smf.ols(formula='target ~ ' + ' + '.join(feature_list), data=data)
      2 fitted = m1.fit(cov_type='HC1')
      3 print(fitted.summary())

~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\base\model.py in from_formula(cls, formula, data, subset, drop_cols, *args, **kwargs)
    153 
    154         tmp = handle_formula_data(data, None, formula, depth=eval_env,
--> 155                                   missing=missing)
    156         ((endog, exog), missing_idx, design_info) = tmp
    157 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\statsmodels\formula\formulatools.py in handle_formula_data(Y, X, formula, depth, missing)
     63         if data_util._is_using_pandas(Y, None):
     64             result = dmatrices(formula, Y, depth, return_type='dataframe',
---> 65                                NA_action=na_action)
     66         else:
     67             result = dmatrices(formula, Y, depth, return_type='dataframe',

~\AppData\Local\Continuum\anaconda3\lib\site-packages\patsy\highlevel.py in dmatrices(formula_like, data, eval_env, NA_action, return_type)
    308     eval_env = EvalEnvironment.capture(eval_env, reference=1)
    309     (lhs, rhs) = _do_highlevel_design(formula_like, data, eval_env,
--> 310                                       NA_action, return_type)
    311     if lhs.shape[1] == 0:
    312         raise PatsyError("model is missing required outcome variables")

~\AppData\Local\Continuum\anaconda3\lib\site-packages\patsy\highlevel.py in _do_highlevel_design(formula_like, data, eval_env, NA_action, return_type)
    163         return iter([data])
    164     design_infos = _try_incr_builders(formula_like, data_iter_maker, eval_env,
--> 165                                       NA_action)
    166     if design_infos is not None:
    167         return build_design_matrices(design_infos, data,

..............
AssertionError: 

0 个答案:

没有答案