Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary
Last synced: 8 months ago · JSON representation ·

Repository

Basic Info
  • Host: GitHub
  • Owner: mvds314
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Size: 48.8 KB
Statistics
  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 2
Created over 3 years ago · Last pushed 10 months ago
Metadata Files
Readme License Citation

README.md

Regression splines

This module includes two spline implementations splines suitable for regression: linear splines using a hinge function basis, and natural cubic splines.

```python 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.01np.random.randn(xobs.shape)

s, res = LinearSpline.fromdata(xobs, yobs, knots=np.linspace(0,np.pi,30), method='OLS', returnestim_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:

bash 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: $hi(x) = \max(x-ki,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. $h1(x)$ sets an initial slope from the first knot onwards. Then next basis function $h2(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:

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:

bash git clone https://github.com/mvds314/regspline.git

Then navigate to the folder containing setup.py and run

bash pip install -e .

to install the package in edit mode.

Run unittests with pytest.

Install the optional dependencies to test all functionality.

Owner

  • Login: mvds314
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "van der Schans"
  given-names: "Martin"
title: "Regspline: a Python library for linear regression splines"
version: <ADD VERSION>
date-released: 2023-01-10
url: "https://github.com/mvds314/regspline"

GitHub Events

Total
  • Release event: 2
  • Watch event: 3
  • Push event: 16
  • Pull request event: 5
  • Create event: 2
Last Year
  • Release event: 2
  • Watch event: 3
  • Push event: 16
  • Pull request event: 5
  • Create event: 2

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 36 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 1
pypi.org: regspline

Regression spline

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 36 Last month
Rankings
Dependent packages count: 9.1%
Average: 30.1%
Dependent repos count: 51.1%
Maintainers (1)
Last synced: 8 months ago

Dependencies

pyproject.toml pypi
  • numpy *
  • pandas *
  • statsmodels *