ModuleNotFoundError: No module named 'sklearn.ensemble.voting_classifier' - python-3.x

I am trying to load a pickle file using below code.
# Load model from file classiferM1 = joblib.load("Model 1_ensemble.pkl")
Now I am facing error
ModuleNotFoundError: No module named 'sklearn.ensemble.voting_classifier'
I understand that sklearn has this module as sklearn.ensemble.VotingClassifier.
Please let me know how I can overcome this error, can I edit the pickle file code?
Thanks and Regards,
Surendra.

You Have Typo mistake the original module name is VotingClassifier but you have written sklearn.ensemble.voting_classifier in your code. Change from sklearn.ensemble import voting_classifier into from sklearn.ensemble import VotingClassifier in your code..

Issue is resolved by installing Anaconda 2.7.

Related

Not able to use SMOTETomek or SMOTEENN - Import Module error

I am trying to import the following libraries:
from imblearn.combine import SMOTEENN
from imblearn.combine import SMOTETomek
Unfortunately I am getting an error that says:
ModuleNotFoundError: No module named 'scipy.special.cython_special'
I have also checked on the following link :https://imbalanced-learn.org/stable/install.html and looks like almost every dependency is installed in my environment.
I am also getting the same error while I am importing Random forest classifier
from sklearn.ensemble import RandomForestClassifier
What could be the issue here?

Getting a Spacy error: No module named 'spacy.pipeline.pipes'; 'spacy.pipeline' is not a package

I'm trying to test a model that is working in another machine, but when I try to import it to my notebook, I get this error:
ModuleNotFoundError: No module named 'spacy.pipeline.pipes'; 'spacy.pipeline' is not a package
We have installed:
Spacy 2.0.18 (Frozen version, Not updatable whatsoever)
And I'm importing:
import spacy
import thinc
import unidecode
import nltk
from spacy.vocab import Vocab
from spacy.language import Language
from spacy.lang.pt import Portuguese
from spacy.lang.en import English
from spacy.pipeline import EntityRecognizer
ner = EntityRecognizer(nlp.vocab)
nlp = Language(Vocab())
nlp = Portuguese()
# Load NER Model
NER_MODEL = pickle.load( open("/ner_model_v022_epoch=706_loss=09o76364626.pkl", "rb" ) )
And I get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-12-83d4770d3e3e> in <module>
---> 40 NER_MODEL = pickle.load( open("/ner_model_v022_epoch=706_loss=09o76364626.pkl", "rb" ) )
ModuleNotFoundError: No module named 'spacy.pipeline.pipes'; 'spacy.pipeline' is not a package
Any ideas why this might be happening? Already installed everything again from 0 but keeps giving me the same error.
Any help will be greatly appreciated.
Close and re-open the Terminal (console).
Activate the venv from the current folder you're working on.
I had this problem come up and found that switching my spacy version from spacy==2.0.18 to spacy==2.1.4 worked! Went back through their releases and spacy.pipeline.pipes isn't present until v2.1.0a8
If you tried to install it via github and you still have that folder, it could cause issues. For me, deleting the spaCy folder helped.

ImportError: cannot import name '_obtain_input_shape' from keras

In Keras,
I'm trying to import _obtain_input_shape as follows:
from keras.applications.imagenet_utils import _obtain_input_shape
However, I get the following error:
ImportError: cannot import name '_obtain_input_shape'
The reason I'm trying to import _obtain_input_shape is so that I can determine the input shape(so as to load VGG-Face as follows :
I'm using it to determine the correct input shape of the input tensor as follow:
input_shape = _obtain_input_shape(input_shape,
default_size=224,
min_size=48,
data_format=K.image_data_format(),
require_flatten=include_top)`
Please assist?
Thanks in advance.
You don't have to downgrade Keras 2.2.2.
In Keras 2.2.2 there is no _obtain_input_shape method in the keras.applications.imagenet_utils module. You can find it under keras-applications with the modul name keras_applications (underscore).
So you don't have to downgrade your Keras to 2.2.0 just change:
from keras.applications.imagenet_utils import _obtain_input_shape
to
from keras_applications.imagenet_utils import _obtain_input_shape
I have found a method that works well. You just use
from keras_applications.imagenet_utils import _obtain_input_shape
Notice: It is keras_applications instead of keras.application.
This issue occured because of the version of keras.
In my case, I was downgrade keras 2.2.2 to 2.2.0, and the problem was solved.
In Colab I solved it by importing Keras and installing :
import keras
!pip install keras_applications
from keras_applications.imagenet_utils import _obtain_input_shape
keras_applications.imagenet_utils is deprecated
Traceback (most recent call last):
File "inception_v3.py", line 36, in
from keras_applications.imagenet_utils import _obtain_input_shape
ModuleNotFoundError: No module named 'keras_application
from keras.applications.imagenet_utils import obtain_input_shape
Not _obtain_input_shape. This works fine with keras==2.5.0rc0 (pip install keras==2.5.0rc0)
for keras 2.2.4:
Change the line like below to make it work.
from keras_applications.imagenet_utils import _obtain_input_shape
Note: It is importing from keras_applications and does not from keras.applications as before.

keras import fails "no module named contrib.ctc"

On OSX El CApitan 10.11.6 I've installed theano & tensorflow fine. But the keras install is not happy as seen from the trace below. I've seen this reported on github issues but with no solution there, only a suggestion to post here on SO.
>>>import theano
>>>
>>> import tensorflow
>>>
>>> import keras
File "/Users/petercotton/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
import tensorflow.contrib.ctc as ctc
ImportError: No module named contrib.ctc`
Suggestions appreciated.
This is a problem with Keras, not TensorFlow and a known issue.
A workaround is mentioned here but that would mean that you have to modify Keras code (keras/backend/tensorflow_backend.py).
Luckily, it seems that this issue is fixed in the master branch of Keras.

Can't import GMM function from sckits.learn

I'm getting error ImportError: No module named gmm when I'm using from scikits.learn.gmm import GMM..
I installed scikits using windows installer and no error..
How I can fix it?
That link is very old, the module name was renamed to sklearn as you have installed version 0.16.1 you should be using
from sklearn.mixture import GMM
as per the docs

Resources