Regression spline
Project description
Regression splines
This module includes two spline implementations splines suitable for regression: linear splines using a hinge function basis, and natural cubic splines.
import numpy as np
import matplotlib.pyplot as plt
from regspline import LinearSpline
plt.close('all')
knots = [0,1,2]
coeffs = [1,2,3]
s = LinearSpline(knots, coeffs)
y=s(np.linspace(0,1))
x=np.linspace(0,np.pi)
y=np.sin(x)
xobs = np.repeat(x,50)
yobs = np.repeat(y,50) + 0.01*np.random.randn(*xobs.shape)
s, res = LinearSpline.from_data(xobs, yobs,
knots=np.linspace(0,np.pi,30),
method='OLS',
return_estim_result=True,
prune=True)
plt.plot(x,y)
plt.plot(x,s(x))
Several regression types are supported to extract the splines from data, including OLS, LASSO, and quantile regression. See the example files.
Installation
You can install this library directly from github:
pip install regspline.git
There are two optional dependencies: scikit-learn, and cvxopt. They are only required to estimate splines on data with, respectively, support vector regressions, and LASSO.
Background
The module contains two splines:
- A linear spline represented by Hinge functions: $h_i(x) = \max(x-k_i,0)$, where $k_i$ are the knots.
- A natural cubic spline.
The splines chosen:
- have coefficents that have a one-to-one correspondence with the knots.
- have the ability that knots can be removed, e.g., when the corresponding coefficient is small or insignificant, without changing the basis functions corresponding to other knots.
- have the ability to represent functions with sparse basis.
One way to interpret, e.g., the linear spline in the hings basis is as follows. $h_1(x)$ sets an initial slope from the first knot onwards. Then next basis function $h_2(x)$ can adjust the slope at the knot $k_2$, if no adjustment is required, its coefficient is insignificant and the knot can be removed from the spline without any impact on the other basis functions.
Related projects
Some projects with related methods:
- basis-expansions
- py-earth
- Quantile regression using decision trees scikit-garden
The module differs from these implementations as it implements the splines as functions, and they are not integrated within an estimation framework.
Development
For development purposes, clone the repo:
git clone https://github.com/mvds314/regspline.git
Then navigate to the folder containing setup.py and run
pip install -e .
to install the package in edit mode.
Run unittests with pytest.
Install the optional dependencies to test all functionality.
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 regspline-25.7.2.tar.gz.
File metadata
- Download URL: regspline-25.7.2.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bc2024677442fc7c834c214610a102417e07398e36c90cf5545d7d72646bac9
|
|
| MD5 |
3a62a1da9fb9bbc4984fdd66ef9a1027
|
|
| BLAKE2b-256 |
1813d075fdc5f262df3a68ff38b7b30f59f7cf105e348ce13ab3074e9286fe19
|
Provenance
The following attestation bundles were made for regspline-25.7.2.tar.gz:
Publisher:
python-publish.yml on mvds314/regspline
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
regspline-25.7.2.tar.gz -
Subject digest:
8bc2024677442fc7c834c214610a102417e07398e36c90cf5545d7d72646bac9 - Sigstore transparency entry: 267674320
- Sigstore integration time:
-
Permalink:
mvds314/regspline@04d726772e18102c51e572481e0f55e398bf401f -
Branch / Tag:
refs/tags/2025.7.2 - Owner: https://github.com/mvds314
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@04d726772e18102c51e572481e0f55e398bf401f -
Trigger Event:
push
-
Statement type:
File details
Details for the file regspline-25.7.2-py3-none-any.whl.
File metadata
- Download URL: regspline-25.7.2-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
991e1c0902dbf9e87b648fdeab1309eede76d5ec6bfe148abc3ac1ce5d908d85
|
|
| MD5 |
181409e885346654baf08ebc68ca167d
|
|
| BLAKE2b-256 |
e068432a26ae79ee0b45b9cb85775e970b4aa08a6e10eec9ed685fb2f6fc1b88
|
Provenance
The following attestation bundles were made for regspline-25.7.2-py3-none-any.whl:
Publisher:
python-publish.yml on mvds314/regspline
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
regspline-25.7.2-py3-none-any.whl -
Subject digest:
991e1c0902dbf9e87b648fdeab1309eede76d5ec6bfe148abc3ac1ce5d908d85 - Sigstore transparency entry: 267674325
- Sigstore integration time:
-
Permalink:
mvds314/regspline@04d726772e18102c51e572481e0f55e398bf401f -
Branch / Tag:
refs/tags/2025.7.2 - Owner: https://github.com/mvds314
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@04d726772e18102c51e572481e0f55e398bf401f -
Trigger Event:
push
-
Statement type: