0

Can not import feature_engine package's module in Kaggle Editor.

(First noting the below lines of codes are working in local machine's Jupyter Notebook, but not in Kaggle )

To Reproduce, I did below inside Kaggle Editor

To install feature_engine just the regular code

!pip install feature_engine

following this link which is same as the official doc.

And then I just have the following code in Kaggle Notebook per the official documentation


from feature_engine import categorical_encoders as ce

After running this cell getting below error.

ImportError: cannot import name 'categorical_encoders' from 'feature_engine' (/opt/conda/lib/python3.7/site-packages/feature_engine/__init__.py)

And this error is coming for any modules of feature_engine . e.g. for the below line as well

from feature_engine import variable_transformers as vt

I am getting error

ImportError: cannot import name 'variable_transformers' from 'feature_engine' (/opt/conda/lib/python3.7/site-packages/feature_engine/__init__.py)

And there's no simple way to upgrade Python to 3.8, as Kaggle does not allow us to specify the python version in it's notebook.

In Kaggle I have the latest version of feature_engine as running !pip show feature_engine gives below

Name: feature-engine
Version: 1.0.2
Summary: Feature engineering package with Scikit-learn's fit transform functionality
Home-page: http://github.com/solegalli/feature_engine
Author: Soledad Galli
Author-email: solegalli@protonmail.com
License: BSD 3 clause
Location: /opt/conda/lib/python3.7/site-packages
Requires: scipy, pandas, statsmodels, scikit-learn, numpy
Required-by: 
Rohan_Paul
  • 1,504
  • 3
  • 29
  • 36

1 Answers1

1

Answering my own question after finding the solution.

Basically, I had to upgrade the version of feature_engine

Feature-engine is in active development regularly publishing new or updated transformers. Hence, ran below to upgrade

$ pip install -U feature-engine

In new version (1.0), we need to import categorical encoders from feature_engine.encoding as below

from feature_engine.encoding import OneHotEncoder

The format below is not used anymore :

from feature_engine import categorical_encoders as ce

Official Doc

Rohan_Paul
  • 1,504
  • 3
  • 29
  • 36