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 git+https://github.com/ensley-nexant/pwlreg.git@main#egg=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.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

pwlreg-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pwlreg-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pwlreg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 971c07e1a33e2fadf24fda5629cd4259bf85ab2c182df87eec87e772b49234ea
MD5 8c607f477d214ca1e43c48a263c48500
BLAKE2b-256 afe9aac2a7464604b6563049f749ef08cb5fff897143922e7b8af8209619e6be

See more details on using hashes here.

Provenance

File details

Details for the file pwlreg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pwlreg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pwlreg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7080d85920502052fe5ee38287003fd2035142af650aa0d0c8da1c3587a01ee6
MD5 01d6389861aa971dde1a2501afd92023
BLAKE2b-256 0fc9ade48675159febdd62cd6944c7931f665ea8cced726f1b1c0522dbf4f9a4

See more details on using hashes here.

Provenance

Supported by

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