Polynomial basis transformers for scikit-learn.
Project description
skpoly
skpoly provides drop-in polynomial feature generators that integrate with scikit-learn pipelines. The library focuses on smooth orthogonal bases such as Bernstein and Legendre polynomials, letting you capture non-linear structure with well-conditioned numerical behavior.
The project expands on the the blog series, beginning with the post “Are polynomial features the root of all evil?”.
Documentation
Explore the documentation.
Quick start
Create a pipeline that first rescales each input dimension and then expands it with Bernstein features before fitting a linear model:
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import MinMaxScaler
from sklearn.linear_model import Ridge
from skpoly import BernsteinFeatures
pipeline = make_pipeline(
MinMaxScaler(),
BernsteinFeatures(degree=8),
Ridge(alpha=1e-2),
)
pipeline.fit(X_train, y_train)
y_pred = pipeline.predict(X_test)
The MinMaxScaler step keeps every feature inside the default [0, 1] range assumed by
the polynomial bases, which in turn preserves the well-conditioned behavior of the
Bernstein and Legendre transforms.
Pairwise interaction features
For multivariate inputs you can enable tensor-product features to model pairwise (and higher-order) interactions between coordinates. Setting tensor_product=True expands the basis with every combination of the univariate polynomials:
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import MinMaxScaler
from sklearn.linear_model import LogisticRegression
from skpoly import LegendreFeatures
pipeline = make_pipeline(
MinMaxScaler(),
LegendreFeatures(degree=5, tensor_product=True),
LogisticRegression(),
)
Development
Clone the repository and install dependencies using uv:
git clone https://github.com/alexshtf/skpoly.git
cd skpoly
uv venv
source .venv/bin/activate
uv sync
Using uv keeps dependency resolution fast and reproducible.
Citation
- Use the
CITATION.cfffile. Most reference managers and services like GitHub's "Cite this repository" option can import the citation metadata directly fromCITATION.cff. - Grab the BibTeX entry. If you prefer to add the reference manually, cite the project as follows.
@software{Shtoff_skpoly_2025,
author = {Alex Shtoff},
title = {skpoly: Polynomial basis transformers for scikit-learn},
url = {https://github.com/alexshtf/skpoly},
version = {0.1.0},
year = {2025}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skpoly-0.1.2.tar.gz.
File metadata
- Download URL: skpoly-0.1.2.tar.gz
- Upload date:
- Size: 115.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6aa9878e19f24b14f97789bbc07f4b01b1657a9bc47898f27734faca19dee0a0
|
|
| MD5 |
b91c2fd811070e7885e4b32d2edf9f06
|
|
| BLAKE2b-256 |
8518cc8df26a38ffc8b6a72ee0098c4be3dac99bfd91b95f8409a4c99f7cb9fd
|
File details
Details for the file skpoly-0.1.2-py3-none-any.whl.
File metadata
- Download URL: skpoly-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e35bf34adc442d52dd1425b8a9efd6ae5a47f2abef976cf6ed183d004ef4f3e
|
|
| MD5 |
7de4907ce0e961e2d259669cf73d16e8
|
|
| BLAKE2b-256 |
1012224ded95cff3c5212ca2c6241a57666f6b50d72f8ec4b80ac297be1dcb91
|