Constrained Linear Regression
constrainedlr is a drop-in replacement for scikit-learn's linear_model.LinearRegression with the extended capability to apply constraints on the model's coefficients, such as signs and lower/upper bounds.
Installation
pip install constrainedlr
Example Usage
Coefficients sign constraints
from constrainedlr import ConstrainedLinearRegression
model = ConstrainedLinearRegression()
model.fit(
X_train,
y_train,
coefficients_sign_constraints={0: "positive", 2: "negative"},
intercept_sign_constraint="positive",
)
y_pred = model.predict(X_test)
print(model.coef_, model.intercept_)
Coefficients range constraints
from constrainedlr import ConstrainedLinearRegression
model = ConstrainedLinearRegression()
model.fit(
X_train,
y_train,
coefficients_range_constraints={
0: {"lower": 2}, # 1st coefficient must be 2 or higher
2: {"upper": 10}, # 3rd coefficient must be smaller than 10
3: {"lower": 0.1, "upper": 0.5}, # 4th coefficient must be between 0.1 and 0.5
},
)
y_pred = model.predict(X_test)
print(model.coef_)
See more in the documentation
Licence
MIT
Metadata
Release files for constrainedlr 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| constrainedlr-0.2.0.tar.gz | 11.1 kB | Without provenance | Details for constrainedlr-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| constrainedlr-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for constrainedlr-0.2.0-py3-none-any.whl |
Total release size: 19.0 kB
Release files / constrainedlr-0.2.0.tar.gz
| Download URL | constrainedlr-0.2.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
734810e9453bcb13cc7cb3c15b947a0cc9094e5fec8f164d1ddbbb1edae1c55c
|
|
BLAKE2b-256 checksum How to use checksums |
6b9a997cd1da88cb8d2e7b194b46850cd89e035c559b3a3cfda11e155c3d46c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.4
|
Release files / constrainedlr-0.2.0-py3-none-any.whl
| Download URL | constrainedlr-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c9f86aebd3db15e7859a9d97af69a5daf68fb8e622885010ed749eff17ff2cb
|
|
BLAKE2b-256 checksum How to use checksums |
e803d1afdadb451c3cb1106b2c2f3cff72017d95f29089be8d54e611b6d92a85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.4
|
Security for constrainedlr 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.