PreTab

PreTab is a modular, scikit-learn-compatible representation and preprocessing library for tabular data. Its focus is feature representation and expansion: splines, neural basis maps, piecewise-linear encoding, kernel approximations, and language embeddings, each shipped as a standalone transformer that speaks the standard fit / transform API. Every PreTab transformer subclasses BaseEstimator and TransformerMixin, so it drops into a Pipeline or ColumnTransformer alongside any sklearn-native transformer you already use.

Note

These docs are for PreTab 1.0.0.

Highlights

🔢 Numerical preprocessing

Spline expansions (B-splines, natural cubic, thin-plate, tensor-product, P-splines), neural basis maps (RBF, ReLU, sigmoid, tanh), custom binning, and Piecewise Linear Encoding (PLE).

🌤 Categorical preprocessing

Ordinal and one-hot encodings, plus pretrained language embeddings for high-cardinality or semantic columns.

🔧 Composable pipelines

Fully compatible with sklearn.pipeline.Pipeline and sklearn.compose.ColumnTransformer; compose standalone representations with scikit-learn transformers and estimators.

🧠 Smart defaults

Automatic feature-type detection (numerical vs. categorical) with support for both pandas.DataFrame and numpy.ndarray inputs.

See it in action

import numpy as np
import pandas as pd
from pretab import Preprocessor

df = pd.DataFrame({
    "age": np.random.randint(18, 65, size=100),
    "income": np.random.normal(60_000, 15_000, size=100).astype(int),
    "city": np.random.choice(["Berlin", "Munich", "Hamburg"], size=100),
})
y = np.random.randn(100)

# One strategy per feature type: PLE for numerics, integer codes for categoricals
pre = Preprocessor(numerical_method="ple", categorical_method="int")
X = pre.fit_transform(df, y)          # single stacked, model-ready array
X.shape
# (100, 15)

Preprocessor detects the column types, fits a strategy per column, and returns a single stacked, model-ready array by default, so it drops straight into a plain sklearn.pipeline.Pipeline; pass output_structure="blocks" for a dict of per-feature blocks instead. Inspect the resolved layout at any time with get_feature_info(verbose=True):

feature  kind         pipeline                        dim   cats
----------------------------------------------------------------
age      numerical    imputer -> minmax -> ple          7      -
income   numerical    imputer -> minmax -> ple          7      -
city     categorical  imputer -> continuous_ordinal     1      4

Mix strategies per column

Columns rarely want the same treatment. Pass a feature_preprocessing map to give each column its own strategy, and a single fit still returns one coherent feature set:

pre = Preprocessor(feature_preprocessing={
    "age": "ple",       # piecewise-linear encoding
    "income": "rbf",    # radial-basis expansion
    "city": "one-hot",  # one-hot categorical
})
X = pre.fit_transform(df, y)

X.shape
# (100, 17)

Get started

Overview

What PreTab is, what it is not, and where it fits.

Overview
Installation

Install PreTab from PyPI or from source.

Installation
Quickstart

Fit and transform a dataset in a few lines.

Quickstart
Nonlinear regression

See PreTab lift a linear model, baseline vs. PreTab.

Nonlinear regression
Representations

The full catalogue of spline and functional expansions, kernel approximations, and encoders.

Representations overview
API reference

The Preprocessor and every transformer.

API reference