Skip to main content

A collection sklearn transformers to encode categorical variables as numeric

Project description

A set of example problems examining different encoding methods for categorical variables for the purpose of classification. Optionally, install the library of encoders as a package and use them in your projects directly. They are all available as methods or as scikit-learn compatible transformers.

Docs [here](

Encoding Methods

  • Ordinal
  • One-Hot
  • Binary
  • Helmert Contrast
  • Sum Contrast
  • Polynomial Contrast
  • Backward Difference Contrast
  • Hashing


Either run the examples in, or install as:

pip install category_encoders

To use:

import category_encoders as ce

encoder = ce.BackwardDifferenceEncoder(cols=[…]) encoder = ce.BinaryEncoder(cols=[…]) encoder = ce.HashingEncoder(cols=[…]) encoder = ce.HelmertEncoder(cols=[…]) encoder = ce.OneHotEncoder(cols=[…]) encoder = ce.OrdinalEncoder(cols=[…]) encoder = ce.SumEncoder(cols=[…]) encoder = ce.PolynomialEncoder(cols=[…])

All of these are fully compatible sklearn transformers, so they can be used in pipelines or in your existing scripts. If the cols parameter isn’t passed, every column will be encoded, so be careful with that.


The datasets used in the examples are car, mushroom, and splice datasets from the UCI dataset repository, found here:




Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for category-encoders, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size category_encoders-1.2.1.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page