我想使用 logit 模型并尝试导入 statsmodels 库。
我的版本:Python 3.6.8
我得到的最好建议是降级 scipy 但不清楚如何降级以及应该降级到什么版本。请帮忙如何解决。https://github.com/statsmodels/statsmodels/issues/5747 https://github.com/statsmodels/statsmodels/issues/5747
import statsmodels.formula.api as smf
ImportError Traceback (most recent call last)
<ipython-input-52-f897a2d817de> in <module>
----> 1 import statsmodels.formula.api as smf
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/formula/api.py in <module>
13 from statsmodels.robust.robust_linear_model import RLM
14 rlm = RLM.from_formula
---> 15 from statsmodels.discrete.discrete_model import MNLogit
16 mnlogit = MNLogit.from_formula
17 from statsmodels.discrete.discrete_model import Logit
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in <module>
43
44 from statsmodels.base.l1_slsqp import fit_l1_slsqp
---> 45 from statsmodels.distributions import genpoisson_p
46
47 try:
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/distributions/__init__.py in <module>
1 from .empirical_distribution import ECDF, monotone_fn_inverter, StepFunction
----> 2 from .edgeworth import ExpandedNormal
3 from .discrete import genpoisson_p, zipoisson, zigenpoisson, zinegbin
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/distributions/edgeworth.py in <module>
5 import numpy as np
6 from numpy.polynomial.hermite_e import HermiteE
----> 7 from scipy.misc import factorial
8 from scipy.stats import rv_continuous
9 import scipy.special as special
ImportError: cannot import name 'factorial'```
更新:升级statsmodels
今天将解决这个问题:pip install statsmodels --upgrade
.
From 这个问题在 statsmodels 的 github 存储库上 https://github.com/statsmodels/statsmodels/issues/5747,解决方案似乎是将 SciPy 降级到版本 1.2(当前版本是 1.3,您似乎正在使用该版本)。
至少对我来说,SciPy 1.2 有factorial
函数在scipy.misc
包裹。
你可以做
python3.6 -m pip install scipy==1.2 --upgrade
Use the --user
如果您没有标准安装权限,请使用该选项。
也许您想避免使用 pip,因为您使用的是 Conda。您也应该能够在 Conda 中固定 scipy 的版本,但是如果您不打算将任何其他包添加到您的环境中,只需使用pip
版本。
当然,降级 SciPy 可能会在其他地方引起问题,但这很难预见,尤其是在不确切知道您安装了哪些其他软件包和依赖项的情况下;你只需要找出答案即可。祈祷不要陷入依赖地狱(因为你已经在门口了)。
对于更好奇的人来说,scipy.misc.factorial
自 1.0 版本以来已被弃用;scipy.special.factorial
应该使用。
然而,在 1.2 版中导入并不会显示任何明确的警告,使用时也不会显示任何明确的警告。这也许可以解释为什么statsmodels
仍然使用旧的导入。下一个修复即将进行statsmodels
发布。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)