How to manually set the range of coefficients on sklearn

1.5k Views Asked by At

I am trying to fit a regression equation of the following type in sklearn

y=ax+bx^2+cx^3+dx^5.......

I have a condition on the range of a i.e a should be between amin and amax. Is there a way to do it?

1

There are 1 best solutions below

0
sply88 On

There is no way to do this using sklearn (that I am aware of).

sklearn.linear_model.LinearRegression only allows non-negative least squares by specifying positive=True in the LinearModel constructor. Under the hood scipy.optimize.nnls is used for this.

However, the constraint linear regression model you want can be estimated using scipy.optimize.lsq_linear.