Skip to content

Add Spline Transformer #17027

@lorentzenchr

Description

@lorentzenchr

Describe the workflow you want to enable

I propose to add a SplineTransformer to preprocessing. This is similiar to PolynomialFeatures, but gives more flexibility (and numerical stability) for linear models to deal with continuous numerical features.

from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import SplineTransformer
from sklearn.pipeline import make_pipeline

# get data X, y
...
model = make_pipeline(SplineTransformer(degree=3, n_knots=20,
                                        positioning='quantile'),
                      LogisticRegression())
model.fit(X, y)

Describe your proposed solution

Add SplineTransformer and internally use scipy for splines. Start with
- 1-dimensional b-splines
- equidistant knots
- quantile based knots

Additional context

Patsy has an implementation of those that matches the R versions.

References

Eilers, Marx "Flexible Smoothing with B-splines and Penalties" passes the scikit-learn inclusion criteria by some margin 😏

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions