Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A collection sklearn transformers to encode categorical variables as numeric

Project Description

[![Travis Status](]( [![Coveralls Status](]( [![CircleCI Status](](

A set of scikit-learn-style transformers for encoding categorical variables into numeric by means of different techniques.

Encoding Methods

  • Ordinal [2][3]
  • One-Hot [2][3]
  • Binary [5]
  • Helmert Contrast [2][3]
  • Sum Contrast [2][3]
  • Polynomial Contrast [2][3]
  • Backward Difference Contrast [2][3]
  • Hashing [1]
  • BaseN [6]
  • LeaveOneOut [4]


The package by itself comes with a single module and an estimator. Before installing the module you will need numpy, statsmodels, and scipy.

To install the module execute:

`shell $ python install `


` pip install category_encoders `


` conda install -c conda-forge 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=[…]) encoder = ce.BaseNEncoder(cols=[…]) encoder = ce.LeaveOneOutEncoder(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 non-numeric column will be encoded. Please see the docs for transformer-specific configuration options.


In the examples directory, there is an example script used to benchmark different encoding techniques on various datasets.

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



BSD 3-Clause


  1. Kilian Weinberger; Anirban Dasgupta; John Langford; Alex Smola; Josh Attenberg (2009). Feature Hashing for Large Scale Multitask Learning. Proc. ICML.
  2. Contrast Coding Systems for categorical variables. UCLA: Statistical Consulting Group. from
  3. Gregory Carey (2003). Coding Categorical Variables, from
  4. Strategies to encode categorical variables with many categories. from
  5. Beyond One-Hot: an exploration of categorical variables. from
  6. BaseN Encoding and Grid Search in categorical variables. from
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
category_encoders-1.2.4.tar.gz (16.1 kB) Copy SHA256 Checksum SHA256 Source Jul 12, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting