Constrained Linear Regression in Python Constrained Linear Regression in Python numpy numpy

Constrained Linear Regression in Python


You mention you would find Lasso Regression or Ridge Regression acceptable. These and many other constrained linear models are available in the scikit-learn package. Check out the section on generalized linear models.

Usually constraining the coefficients involves some kind of regularization parameter (C or alpha)---some of the models (the ones ending in CV) can use cross validation to automatically set these parameters. You can also further constrain models to use only positive coefficents---for example, there is an option for this on the Lasso model.


scipy-optimize-leastsq-with-bound-constraintson SO gives leastsq_bounds, which is scipy leastsq+ bound constraints such as 0 <= x_i <= 255.
(Scipy leastsq wraps MINPACK, one of several implementations of the widely-used Levenberg–Marquardt algorithma.k.a. damped least-squares.
There are various ways of implementing bounds; leastsq_bounds is I think the simplest.)