Skip to main content

A scikit-learn-compatible implementation of Piecewise Linear Regression

Project description

pwlreg

Tests codecov

A scikit-learn-compatible implementation of Piecewise Linear Regression

Installation

pip install pwlreg

Documentation

See the documentation here.

import numpy as np
import matplotlib.pyplot as plt

import pwlreg as pw


x = np.array([1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
y = np.array([1., 1.5, 0.5, 1., 1.25, 2.75, 4, 5.25, 6., 8.5])

m = pw.AutoPiecewiseRegression(n_segments=2, degree=[0, 1])
m.fit(x, y)

xx = np.linspace(1, 10, 100)
plt.plot(x, y, "o")
plt.plot(xx, m.predict(xx), "-")
plt.show()

pwlreg toy example

m.coef_         # [ 1.00  -5.50  1.35 ]
m.breakpoints_  # [ 1.000000  4.814815  10.000000 ]

$$ x = \begin{cases} 1, & 1 \leq x < 4.815 \ -5.5 + 1.35x, & 4.815 \leq x < 10 \end{cases} $$

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pwlreg-1.0.3.tar.gz (240.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pwlreg-1.0.3-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pwlreg-1.0.3.tar.gz.

File metadata

  • Download URL: pwlreg-1.0.3.tar.gz
  • Upload date:
  • Size: 240.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pwlreg-1.0.3.tar.gz
Algorithm Hash digest
SHA256 543c4e007d4449c58a1382d2a794270ee9b2272f613ba12c4cee4c652e4a0366
MD5 577956ca9dddfe9a293526837557e816
BLAKE2b-256 777f448c8fbb0366c82ddb0e8b89909980af8b8e50dc89996f395ed904d3edb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pwlreg-1.0.3.tar.gz:

Publisher: release.yml on ensley-nexant/pwlreg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pwlreg-1.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: pwlreg-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pwlreg-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ce4343b322e594e9a2e09a5fecee15a4bc0b031e5208d893e33735cb810dbbc0
MD5 29d21ecf2c79bd8d09231e6acb5e2b34
BLAKE2b-256 6ca068307f4c841df83c4a83b3b1445353469c82b8fd4b4d80c5477d406959e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pwlreg-1.0.3-py2.py3-none-any.whl:

Publisher: release.yml on ensley-nexant/pwlreg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page