Skip to main content

PARC - Piecewise Affine Regression and Classification

Project description

PyPARC - A Python Package for Piecewise Affine Regression and Classification

Contents

Package description

PyPARC is a package for solving multivariate regression and classification problems using piecewise linear (affine) predictors over a polyhedral partition of the feature space. The underlying algorithm is called PARC (Piecewise Affine Regression and Classification) and is described in the following paper:

[1] A. Bemporad, "A piecewise linear regression and classification algorithm with application to learning and model predictive control of hybrid systems," IEEE Transactions on Automatic Control, vol. 68, pp. 3194–3209, June 2023. [bib entry]

The algorithm alternates between:

  1. Solving ridge regression problems (for numeric targets) and softmax regression problems (for categorical targets), and either softmax regression or cluster centroid computation for piecewise linear separation
  2. Assigning the training points to different clusters on the basis of a criterion that balances prediction accuracy and piecewise-linear separability.

For earlier Python versions of the code, see here.

Installation

pip install pyparc

Basic usage

Say we want to fit a piecewise affine model on a dataset of 1000 samples $(x,y)$, where $x=(x_1,x_2)$ has two numeric components randomly generated between 0 and 1, and $y$ is obtained by the following nonlinear function of $x$

$$y(x_1,x_2)=\sin\left(4x_{1}-5\left(x_{2}-\frac{1}{2}\right)^2\right)+2x_2$$

drawing drawing

We use 80% of the data for training (X_train,Y_train) and 20% for testing the model (X_test,Y_test).

We want to train a piecewise affine model on a polyhedral partition with maximum 10 regions, with $\ell_2$-regularization coefficient $\alpha=10^{-4}$ and maximum 15 block-coordinate descent iterations of the algorithm:

from parc.parc import PARC

predictor = PARC(K=10, alpha=1.0e-4, maxiter=15) # initialize PARC object

categorical = False # targets are numeric

# fit piecewise linear predictor
predictor.fit(X_train, Y_train) 

# make predictions on test data
Yhtest, _ = predictor.predict(X_test) 

# compute R2 scores
score_train = predictor.score(X_train, Y_train)  
score_test = predictor.score(X_test, Y_test)  

The resulting PWA model leads to the following partition drawing

and PWA function

drawing drawing

Contributors

This package was coded by Alberto Bemporad.

This software is distributed without any warranty. Please cite the above papers if you use this software.

Citing PARC

@article{Bem23,
    author={A. Bemporad},
    title={A Piecewise Linear Regression and Classification Algorithm with Application to Learning and Model Predictive Control of Hybrid Systems},
    journal={IEEE Transactions on Automatic Control},
    year=2023,
    month=jun,
    volume=68,
    number=6,
    pages={3194--3209},
}

License

Apache 2.0

(C) 2021-2023 A. Bemporad

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

pyparc-2.0.4.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

pyparc-2.0.4-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file pyparc-2.0.4.tar.gz.

File metadata

  • Download URL: pyparc-2.0.4.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pyparc-2.0.4.tar.gz
Algorithm Hash digest
SHA256 00727f1dce62a1a2bc7e662f1907f39ed1270a2cd52d2dc9fd464f1c30d32119
MD5 abbcd084de076904bae40627d74d8e98
BLAKE2b-256 d6430b896ea88246776ef61be0cdf51affbfd8eaae440848f1597c1b06064915

See more details on using hashes here.

File details

Details for the file pyparc-2.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyparc-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pyparc-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 04c822f369ac523a1d1453f6a8cae4095d853d80ff68bdf5adb4e77e25cdae4f
MD5 0d1f6dfa73fb4ff304ffdb3e956a5e78
BLAKE2b-256 86d9c3fd95c0756ed869a10ec657c8e0516eb07ca524d80170b38e9244357d12

See more details on using hashes here.

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