在Python中导入Statsmodel时出错

时间:2018-04-05 11:18:54

标签: python python-3.x python-import statsmodels

我目前正在尝试使用Python中的statsmodels模块将ARMA模型拟合到某些数据。但是,问题是它无法加载包,只返回AttributeError,表明:

  File "C:\Projects\Python\KalmanFilteringDataFusion\armaTest.py", line 5, in <module>
    from statsmodels.tsa.arima_model import ARIMA
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\statsmodels\tsa\arima_model.py", line 30, in <module>
    from statsmodels.tsa.ar_model import AR
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\statsmodels\tsa\ar_model.py", line 608, in <module>
    class ARResults(tsbase.TimeSeriesModelResults):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\statsmodels\tsa\ar_model.py", line 811, in ARResults
    preddoc = AR.predict.__doc__.split('\n')
AttributeError: 'NoneType' object has no attribute 'split'

我唯一要做的就是尝试将ARIMA模块导入为:

from statsmodels.tsa.arima_model import ARIMA

如果我尝试导入另一个statmodels子模块(例如import statsmodels.formula.api as smf),它将返回:

  File "C:\Projects\Python\KalmanFilteringDataFusion\armaTest.py", line 5, in <module>
    import statsmodels.formula.api as smf
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\statsmodels\formula\api.py", line 15, in <module>
    from statsmodels.discrete.discrete_model import MNLogit
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\statsmodels\discrete\discrete_model.py", line 146, in <module>
    class DiscreteModel(base.LikelihoodModel):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\statsmodels\discrete\discrete_model.py", line 208, in DiscreteModel
    fit.__doc__ += base.LikelihoodModel.fit.__doc__
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'NoneType'

如果我只是做import statsmodelsimport statsmodels.tsa,它就可以很好地导入它,所以我想这个错误位于ARIMA“子模块”的某处。

有人对错误有任何建议吗?还有什么潜在的解决办法吗?

1 个答案:

答案 0 :(得分:1)

我使用Sublime Text 3编译Python,并且显然是“Python3”构建文件,导致错误。当我切换到“Python”-builder时,系统编译得很好。除了一些警告关于pandas放弃了对statsmodels中实现DateTime的方式的支持。

如果遇到同样的情况,请尝试切换构建器。当我弄清楚为什么会这样时,我会告诉你。因为它真的很奇怪。