I'm trying to do a logistic regression using statsmodels & an unable to import. I'm using statsmodels v0.8.0 with Python 3.x in a Jupyter notebook. How am I able to import correctly?
ImportError Traceback (most recent call last)
<ipython-input-47-6030a6549dc0> in <module>()
----> 1 import statsmodels.api as sm
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/api.py in <module>()
3 from . import tools
4 from .tools.tools import add_constant, categorical
----> 5 from . import regression
6 from .regression.linear_model import OLS, GLS, WLS, GLSAR
7 from .regression.recursive_ls import RecursiveLS
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/regression/__init__.py in <module>()
----> 1 from .linear_model import yule_walker
2
3 from statsmodels import NoseWrapper as Tester
4 test = Tester().test
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in <module>()
51 cache_readonly,
52 cache_writable)
---> 53 import statsmodels.base.model as base
54 import statsmodels.base.wrapper as wrap
55 from statsmodels.emplike.elregress import _ELRegOpts
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/base/model.py in <module>()
8 from statsmodels.stats.contrast import ContrastResults, WaldTestResults
9 from statsmodels.tools.decorators import resettable_cache, cache_readonly
---> 10 import statsmodels.base.wrapper as wrap
11 from statsmodels.tools.numdiff import approx_fprime
12 from statsmodels.tools.sm_exceptions import ValueWarning, \
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/base/wrapper.py in <module>()
3
4 import numpy as np
----> 5 from statsmodels.compat.python import get_function_name, iteritems, getargspec
6
7 class ResultsWrapper(object):
ImportError: cannot import name 'getargspec'
Related
I tried to install segmentation-models using.
!pip install -U segmentation-models==0.2.1
import tensorflow as tf
import tensorflow.keras as keras
print(tf.__version__)
print(keras.__version__)
Output:
2.4.1
2.4.0
# Tried for import
import segmentation_models as sm
Resulted in error: ModuleNotFoundError: No module named 'keras.legacy'
Following is the stack trace
stack Trace:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-16-7b5049dd4be0> in <module>()
----> 1 import segmentation_models as sm
6 frames
/usr/local/lib/python3.7/dist-packages/segmentation_models/__init__.py in <module>()
4
5 from .unet import Unet
----> 6 from .fpn import FPN
7 from .linknet import Linknet
8 from .pspnet import PSPNet
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/__init__.py in <module>()
----> 1 from .model import FPN
2
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/model.py in <module>()
----> 1 from .builder import build_fpn
2 from ..backbones import get_backbone, get_feature_layers
3 from ..utils import freeze_model
4 from ..utils import legacy_support
5
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/builder.py in <module>()
6 from keras.models import Model
7
----> 8 from .blocks import pyramid_block
9 from ..common import ResizeImage
10 from ..common import Conv2DBlock
/usr/local/lib/python3.7/dist-packages/segmentation_models/fpn/blocks.py in <module>()
1 from keras.layers import Add
2
----> 3 from ..common import Conv2DBlock
4 from ..common import ResizeImage
5 from ..utils import to_tuple
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/__init__.py in <module>()
1 from .blocks import Conv2DBlock
----> 2 from .layers import ResizeImage
/usr/local/lib/python3.7/dist-packages/segmentation_models/common/layers.py in <module>()
2 from keras.engine import InputSpec
3 from keras.utils import conv_utils
----> 4 from keras.legacy import interfaces
5 from keras.utils.generic_utils import get_custom_objects
6
ModuleNotFoundError: No module named 'keras.legacy'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Solution Tried:
To downgrade both tensorflow and keras to
!pip install tensorflow==2.2.0
!pip install keras==2.3.1
But it is creating conflict between the tensorflow.keras and keras.
Is there any way to work this using tensorflow.keras?
As of now the following approach is working.
Do not try with specific version of segmentation_models module.
#install this way
!pip3 install tensorflow==2.2
!pip3 install keras==2.3.1
!pip3 install -U segmentation-models
import tensorflow as tf
import tensorflow.keras as keras
import segmentation_models as sm
Now segmentation_models imported successfully.
I am trying to use Keras on my machine but I keep getting the error message
"AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'".
Stack Trace is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-dd13cebc6f04> in <module>
----> 1 import acgan
~/Documents/GitHub/Keras-GAN/acgan/acgan.py in <module>
1 from __future__ import print_function, division
2
----> 3 from keras.datasets import mnist
4 from keras.layers import Input, Dense, Reshape, Flatten, Dropout, multiply
5 from keras.layers import BatchNormalization, Activation, Embedding, ZeroPadding2D
/anaconda3/lib/python3.6/site-packages/keras/__init__.py in <module>
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
/anaconda3/lib/python3.6/site-packages/keras/utils/__init__.py in <module>
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7 from . import losses_utils
8 from . import metrics_utils
/anaconda3/lib/python3.6/site-packages/keras/utils/conv_utils.py in <module>
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11
/anaconda3/lib/python3.6/site-packages/keras/backend/__init__.py in <module>
----> 1 from .load_backend import epsilon
2 from .load_backend import set_epsilon
3 from .load_backend import floatx
4 from .load_backend import set_floatx
5 from .load_backend import cast_to_floatx
/anaconda3/lib/python3.6/site-packages/keras/backend/load_backend.py in <module>
88 elif _BACKEND == 'tensorflow':
89 sys.stderr.write('Using TensorFlow backend.\n')
---> 90 from .tensorflow_backend import *
91 else:
92 # Try and load external backend.
/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in <module>
52
53 # Private TF Keras utils
---> 54 get_graph = tf_keras_backend.get_graph
55 # learning_phase_scope = tf_keras_backend.learning_phase_scope #
TODO
56 name_scope = tf.name_scope
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
I googled the issue and found this
https://forums.xilinx.com/t5/Deephi-DNNDK/Module-tensorflow-python-keras-backend-has-no-attribute-get/td-p/1022555
which tells me that it is tensorflow version related, but not which version to use. I am using Python3 on MacOS.
Thank you for your help.
I couldn't reproduce the error you observe with Keras 2.3.0 & tensorflow 2.0.0rc1. Although, I was able to start the training of acgan, I got a different error after one iteration: Resource localhost/_AnonymousVar84/N10tensorflow3VarE does not exist.
I could successfully run the example with the following versions:
Keras 2.2.4/tensorflow 1.14.0
tensorflow 2.0.0rc1 and replace keras with tensorflow.keras in the imports.
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.
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
I am trying to do this:
from sklearn.model_selection import train_test_split
and getting an error:
In [31]: from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-31-73edc048c06b> in <module>()
----> 1 from sklearn.model_selection import train_test_split
/usr/local/lib/python3.6/site-packages/sklearn/model_selection/__init__.py in <module>()
----> 1 from ._split import BaseCrossValidator
2 from ._split import KFold
3 from ._split import GroupKFold
4 from ._split import StratifiedKFold
5 from ._split import TimeSeriesSplit
/usr/local/lib/python3.6/site-packages/sklearn/model_selection/_split.py in <module>()
29 from ..externals.six import with_metaclass
30 from ..externals.six.moves import zip
---> 31 from ..utils.fixes import signature, comb
32 from ..base import _pprint
33
ImportError: cannot import name 'comb'
any help would be much apreciated.
SciPy >=0.19 uses from scipy.special import comb instead of from scipy.misc import comb. https://github.com/scikit-learn/scikit-learn/pull/9046
utils/fixes.py source
try: # SciPy >= 0.19
from scipy.special import comb, logsumexp
except ImportError:
from scipy.misc import comb, logsumexp # noqa
I had the same error. conda remove --name your environment --all. Next, re-install the environment. It worked for me.
from sklearn.linear_model import LinearRegression
gives me this error in Jupyter Notebook:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-127-36ba82e2d702> in <module>()
----> 1 from sklearn.linear_model import LinearRegression
2
3 lin_reg = LinearRegression()
4 lin_reg.fit(housing_prepared, housing_labels)
C:\Users\David\Anaconda2\lib\site-packages\sklearn\linear_model\__init__.py in <module>()
19 MultiTaskElasticNet, MultiTaskElasticNetCV,
20 MultiTaskLassoCV)
---> 21 from .huber import HuberRegressor
22 from .sgd_fast import Hinge, Log, ModifiedHuber, SquaredLoss, Huber
23 from .stochastic_gradient import SGDClassifier, SGDRegressor
C:\Users\David\Anaconda2\lib\site-packages\sklearn\linear_model\huber.py in <module>()
10 from ..utils import check_X_y
11 from ..utils import check_consistent_length
---> 12 from ..utils import axis0_safe_slice
13 from ..utils.extmath import safe_sparse_dot
14
ImportError: cannot import name axis0_safe_slice
I can import things from sklearn.preprocessing fine. Thanks for your help!
Don't know what the exact issue was, but uninstalling and reinstalling scikit-learn fixed this for me:
pip uninstall scikit-learn
pip install scikit-learn