Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import category_encoders module

I am not able to import category_encoders module in jupyter notebook in python 3 virtual environment.

Error

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-15-86725efc8d1e> in <module>()
      9 from plotly import graph_objs
     10 from datetime import datetime
---> 11 import category_encoders as ce
     12 
     13 import sklearn

ModuleNotFoundError: No module named 'category_encoders'

Output of "which pip"

/opt/virtual_env/py3/bin/pip

Output of "pip show category_encoders" is

Name: category-encoders
Version: 1.3.0
Summary: A collection sklearn transformers to encode categorical variables as numeric
Home-page: https://github.com/wdm0006/categorical_encoding
Author: Will McGinnis
Author-email: [email protected]
License: BSD
Location: /opt/virtual_env/py3/lib/python3.6/site-packages
Requires: numpy, pandas, statsmodels, scikit-learn, patsy, scipy
Required-by: 

Output of "pip list"

Package             Version
------------------- -------
absl-py             0.7.0  
astor               0.7.1  
backcall            0.1.0  
category-encoders   1.3.0  
cycler              0.10.0 
like image 627
joel Avatar asked Jan 19 '19 09:01

joel


2 Answers

pip install --upgrade category_encoders

Now, Restart your kernel

import category_encoders as... so on and so forth

Also, you can checkout the sk-learn's preprocessing class CategoricalEncoder...

from sklearn.preprocessing import CategoricalEncoder

get sk-learn from here,

pip install git+git://github.com/scikit-learn/scikit-learn.git

or Simply

pip install sklearn

like image 193
Aditya Patnaik Avatar answered Oct 31 '22 21:10

Aditya Patnaik


I was using anaconda environment.

Initially, I installed category_encoders using pip (within the conda enviornment) and it failed to resolve. Then I uninstalled ``category_encoders` from pip

pip uninstall category-encoders

and installed it using conda:

conda install -c conda-forge category_encoders

That solved the issue.

like image 28
Arnab Biswas Avatar answered Oct 31 '22 22:10

Arnab Biswas