在运行OLS回归时使用dask的数据时出现NotImplementedError

时间:2018-06-21 17:29:22

标签: python statsmodels dask

我想要做的实际上很简单。我想通过使用dask的数据来运行OLS回归。没关系,如果我只是将数据安装到dask数据框中,或者使用了pandas(但是使用Pandas时出现内存错误)。

# import modules
import statsmodels.formula.api as smf
import dask.dataframe as dd

df = dd.read_csv(input_file)
mod = smf.ols(formula='lnq ~ lnp + lnp:C(product_code)+ C(product_code)', data=df)
results = mod.fit(cov_type = 'cluster', cov_kwds={'groups': df['product_code']})
print(results.summary())

但是,出现以下错误:

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "H:/yoox_3.py", line 11, in <module>
    mod = smf.ols(formula='lnq ~ lnp + lnp:C(product_code)+ C(product_code)', data=df)

  File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\base\model.py", line 155, in from_formula
    missing=missing)

  File "C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\formula\formulatools.py", line 68, in handle_formula_data
    NA_action=na_action)

  File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\highlevel.py", line 310, in dmatrices
    NA_action, return_type)

  File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\highlevel.py", line 165, in _do_highlevel_design
    NA_action)

  File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\highlevel.py", line 70, in _try_incr_builders
    NA_action)

  File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\build.py", line 696, in design_matrix_builders
    NA_action)

  File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\build.py", line 448, in _examine_factor_types
    done = cat_sniffers[factor].sniff(value)

  File "C:\ProgramData\Anaconda3\lib\site-packages\patsy\categorical.py", line 204, in sniff
    for value in data:

  File "C:\ProgramData\Anaconda3\lib\site-packages\dask\dataframe\core.py", line 1703, in __getitem__
    raise NotImplementedError()

NotImplementedError

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我不认为statsmodels支持dask数据框