lpspline
Project description
LPSpline
LPSpline is a Python package for building and optimizing linear spline models using an intuitive additive API. It provides a flexible way to model non-linear relationships using various spline types like Piecewise Linear, B-Splines, Cyclic Splines, and Categorical Factors.
Installation
Install lpspline via pip directly from the repository, or if published:
pip install lpspline
(Note: If not yet on PyPI, install via pip install . in the project root)
Quick Start
LPSpline allows you to easily compose additive models. Here's a quick example:
import numpy as np
import polars as pl
from lpspline import l, pwl, bs
# 1. Prepare Data
# Suppose df is a Polars DataFrame with columns "x1", "x2", "x3", and "target"
df = pl.DataFrame({
"x1": np.linspace(0, 10, 100),
"x2": np.random.rand(100) * 10,
"x3": np.linspace(0, 20, 100),
"target": np.sin(np.linspace(0, 10, 100)) + np.random.normal(0, 0.1, 100)
})
# 2. Define Components
model = (
l("x1", bias=True) +
pwl("x2", knots=[5.0]) +
bs("x3", knots=np.linspace(0, 20, 5), degree=3)
)
# 3. Fit the Model
model.fit(df, df["target"])
# 4. Predict
predictions = model.predict(df)
Expected output
Once the model is fitted, you will see a detailed summary to the console:
==================================================
✨ Model Summary ✨
==================================================
Problem Status: optimal
--------------------------------------------------
Spline Type | Term | Params
--------------------------------------------------
🟢 Linear | x1 | 2
🟢 Piecewise | x2 | 2
🟢 BSpline | x3 | 5
--------------------------------------------------
📊 Total Parameters | 9
==================================================
Demo with multiple variables
Inside the notebook/ folder you will find a demo.ipynb file which plots the learned spline components automatically:
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 lpspline-0.0.1.tar.gz.
File metadata
- Download URL: lpspline-0.0.1.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67e2bd344acf084fc407c88b7c6e35e5faed2de461b70fdf5c12fc7be99f287d
|
|
| MD5 |
d6e2f4501eff682a2a3c2a689b2a5b82
|
|
| BLAKE2b-256 |
e1f489ada079e952c718f34842aa8e42b6ea9bfbe458c52fbdaeb89ae77744df
|
File details
Details for the file lpspline-0.0.1-py3-none-any.whl.
File metadata
- Download URL: lpspline-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a72302f49b14beafa3d31831f851a1fc8802b3621b323d3907bd899b3226b2f9
|
|
| MD5 |
9ad249da493ea4914f2d6f9202bdbc5d
|
|
| BLAKE2b-256 |
60f581502319f60ef7922e6a4a4b9cda18eed92f49e1d814953cb10ccd607f71
|