Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this error while using statsmodels" ImportError: cannot import name 'factorial'"?

I have already gone through this answer While importing auto_arima from pmdarima: ERROR : cannot import name 'factorial' from 'scipy.misc' but couldn't fix the error,I do not understand how to use developer version. Is there any other method for applying Seasonal ARIMA model?

import statsmodels.api as sm
mod = sm.tsa.statespace.SARIMAX(train_weekly.Price,
                                order=(1, 0, 0),
                                seasonal_order=(1, 1, 0, 12),
                                enforce_stationarity=False,
                                enforce_invertibility=False)

results = mod.fit()
print(results.summary().tables[0])
print(results.summary().tables[1])

Following is the output

ImportError                               Traceback (most recent call last)
<ipython-input-30-a5d9120bdc57> in <module>()
----> 1 import statsmodels.api as sm
      2 mod = sm.tsa.statespace.SARIMAX(train_weekly.Price,
      3                                 order=(1, 0, 0),
      4                                 seasonal_order=(1, 1, 0, 12),
      5                                 enforce_stationarity=False,

3 frames
/usr/local/lib/python3.6/dist-packages/statsmodels/api.py in <module>()
     14 from . import robust
     15 from .robust.robust_linear_model import RLM
---> 16 from .discrete.discrete_model import (Poisson, Logit, Probit,
     17                                       MNLogit, NegativeBinomial,
     18                                       GeneralizedPoisson,

/usr/local/lib/python3.6/dist-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:

/usr/local/lib/python3.6/dist-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

/usr/local/lib/python3.6/dist-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'

I just want to use seasonal ARIMA,if there is any other way please help me. Thanks.

like image 484
Aditya Mahajan Avatar asked May 22 '19 06:05

Aditya Mahajan


1 Answers

Seems like there is a version mismatch of scipy module. Try downgrading scipy module.

In windows execute the following command in Administrative mode,

pip3 install --user scipy==1.2.0

If you're using Linux,

python3.6 -m pip install scipy==1.2 --upgrade
like image 93
Isuru Hemantha Avatar answered Nov 12 '22 06:11

Isuru Hemantha