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
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).
Ordinal and one-hot encodings, plus pretrained language embeddings for high-cardinality or semantic columns.
Fully compatible with sklearn.pipeline.Pipeline and sklearn.compose.ColumnTransformer;
compose standalone representations with scikit-learn transformers and estimators.
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
What PreTab is, what it is not, and where it fits.
Install PreTab from PyPI or from source.
Fit and transform a dataset in a few lines.
See PreTab lift a linear model, baseline vs. PreTab.
The full catalogue of spline and functional expansions, kernel approximations, and encoders.
The Preprocessor and every transformer.
Project links
Source code: https://github.com/OpenTabular/PreTab
Issue tracker: https://github.com/OpenTabular/PreTab/issues