A scikit-learn-compatible implementation of Piecewise Linear Regression
Project description
pwlreg
A scikit-learn-compatible implementation of Piecewise Linear Regression
Installation
pip install pwlreg
Documentation
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()
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
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
pwlreg-1.0.1.tar.gz
(7.8 kB
view details)
Built Distribution
File details
Details for the file pwlreg-1.0.1.tar.gz
.
File metadata
- Download URL: pwlreg-1.0.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22145c7e3d18fb4dcdd97cabaf05ebc4e6a73f68bc4db2ee229021eaa8817b35 |
|
MD5 | f319817b2dd3795eb36748153853eb15 |
|
BLAKE2b-256 | ddc3649b05aff3ad95ad02f6f32386bcee7f3e5c9d4e1369e86244caf4b3257d |
Provenance
File details
Details for the file pwlreg-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pwlreg-1.0.1-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.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c35abfaf3657b2988addf4b1bf42fedf93de3446645f484df5e5fe5546c79a8 |
|
MD5 | 2969dad5459132d05c1a2c20790caaab |
|
BLAKE2b-256 | 47971f2125890ef96e2cc02c2c11911482c384e8e4b24d8c7f00bcde5ee082b1 |