Metadata-Version: 2.1
Name: constrainedlr
Version: 0.2.0
Summary: Constrained Linear Regression with sklearn-compatible API
Author-email: Theodore Tsitsimis <th.tsitsimis@gmail.com>
Project-URL: Homepage, https://github.com/tsitsimis/constrainedlr
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENCE
Requires-Dist: numpy>=1.18.0
Requires-Dist: scikit-learn>=1.2.2
Requires-Dist: cvxopt>=1.3.1
Requires-Dist: pandas>=1.2.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: jupyter; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: coverage; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: diff_cover; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: build; extra == "dev"

# Constrained Linear Regression
<a href="https://pypi.org/project/constrainedlr" target="_blank">
    <img src="https://img.shields.io/pypi/v/constrainedlr?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://pypi.org/project/constrainedlr" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/constrainedlr.svg?color=%2334D058" alt="Supported Python versions">
</a>

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
```bash
pip install constrainedlr
```

## Example Usage

### Coefficients sign constraints
```python
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
```python
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](https://tsitsimis.github.io/constrainedlr/)


### Licence
MIT
