category_encoders is a Python library for converting categorical variables into numerical features while preserving scikit-learn-compatible workflows. It extends standard preprocessing options with strategies such as one-hot, greedy target, and leave-one-out target encoding. section 8.1.4
Use it inside pipelines and column transformers: scale continuous columns separately, encode selected categorical columns, and pass the resulting features to compatible machine-learning estimators. section 8.1.4
A practical preprocessing workflow is:
- Identify categorical and continuous columns, then split the data into training and test sets. section 8.1.4
- Place a category_encoders encoder in a pipeline and combine it with other column-specific transformations through ColumnTransformer. section 8.1.4
- Fit preprocessing on training data, transform both partitions, and evaluate the downstream estimator on held-out features. section 8.1.4
Australian Credit Approval
On a binary credit-approval task, one-hot encoding produced 38 features and 89.855% random-forest accuracy. Greedy target encoding reduced the representation to 14 features and reached 91.304%; leave-one-out target encoding also used 14 features and reached 90.580%. section 8.1.4
import category_encoders as ce
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
preprocess_continuous = Pipeline(steps=[('scaler', StandardScaler())])
preprocess_categorical = Pipeline(steps=[('encoder',
ce.OneHotEncoder(cols=cat_features))])
Inspect the compact pipeline that combines StandardScaler with category_encoders.OneHotEncoder. section 8.1.4

