Skip to main content
1 of 3
Sextus Empiricus
  • 86.4k
  • 6
  • 115
  • 301

Your approach with the extra parameters will be problematic as multiple values for the coefficients will provide a same solution (the solution won't be unique).

Non-negative least squares regression is often solved by an active set method that updates in steps the active constraints (see for instance How do Lawson and Hanson solve the unconstrained least squares problem?). In those steps various regukar least squares estimates are computed for different active sets. Those steps will fail with your approach because of the multiple solutions (you will get some errors during the computations like non-invertible matrices).

An alternative nnls for Python (asside from Galen's response) could be glmnet which has been ported to Python. In R you can set upper and lower limits and with a zero penalty it becomes equivalent to non-negative least squares regression (albeit probably less efficient on computational resources than the faster algorithms specific for non negative least squares).

Sextus Empiricus
  • 86.4k
  • 6
  • 115
  • 301