0

I was trying to import Categorical Encoder in sklearn

from sklearn.preprocessing import CategoricalEncoder

But I get the error

ImportError: cannot import name 'CategoricalEncoder' from 'sklearn.preprocessing' (D:\ProgramData\Miniconda3\lib\site-packages\sklearn\preprocessing\__init__.py)

I have version 0.21.3 of sklearn.

I checked online to see the documentation and it seems that CategoricalEncoder was there in version 0.20.dev0 (https://15359-843222-gh.circle-artifacts.com/0/home/ubuntu/scikit-learn/doc/_build/html/stable/modules/generated/sklearn.preprocessing.CategoricalEncoder.html) But is not there in 0.21.3 (https://scikit-learn.org/stable/modules/classes.html#module-sklearn.preprocessing)

What happened to CategoricalEncoder? Is there a way I can still use it? Like can I import 2 versions of sklearn and pull it from the 0.20.dev0 version

Alhpa Delta
  • 3,385
  • 4
  • 16
  • 31

2 Answers2

3

CategoricalEncoder is only available in the development version 0.20.dev0. Use OneHotEncoder and OrdinalEncoder insted.(see #10521)

Amine Benatmane
  • 1,191
  • 1
  • 8
  • 15
0

We can import categorical encoder library directly. For example:

import category_encoders as ce

[If category_encoders is not installed first we need to install it ]

pip install category_encoders

https://pypi.org/project/category-encoders/

moken
  • 3,227
  • 8
  • 13
  • 23