New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

constrainedlr

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

constrainedlr

Constrained Linear Regression with sklearn-compatible API

  • 0.2.0
  • PyPI
  • Socket score

Maintainers
1

Constrained Linear Regression

Package version Supported Python versions

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc