scikit-learn-contrib/category_encoders

A library of sklearn compatible categorical variable encoders

What it solves

Machine learning models require numerical input, but real-world data often contains categorical variables (like "country" or "gender"). This library provides a collection of tools to convert these categories into numeric formats so they can be processed by machine learning algorithms.

How it works

The library offers a suite of scikit-learn-style transformers. These tools can be integrated directly into existing scikit-learn pipelines or scripts. They support both unsupervised methods (which transform data based on the categories themselves) and supervised methods (which use the target variable to inform the transformation). The encoders automatically detect categorical columns in your pandas dataframes or numpy arrays unless you specify otherwise.

Who it’s for

This project is for data scientists and machine learning engineers who use the scikit-learn ecosystem and need to perform feature engineering on categorical data. It is particularly useful for those who need to move beyond basic one-hot encoding to more advanced techniques like target encoding or weight of evidence.

Highlights

  • Fully compatible with scikit-learn pipelines and transformers.
  • Includes a wide variety of unsupervised encoding methods like Binary, Hashing, and various Contrast encodings.
  • Provides advanced supervised encoding methods, including Target Encoding, CatBoost, and LeaveOneOut.
  • Includes helper wrappers like NestedCVWrapper to help prevent overfitting during the encoding process.

Related

  • Project
  • Project
  • Project
  • Project
  • Project