title: Constrained Linear Regression in Python
body: <p>I have a <a href="http://en.wikipedia.org/wiki/Linear_regression" rel="noreferrer">classic linear</a> regression problem of the form:</p>
  
  <p><code>y = X b</code></p>
  
  <p>where <code>y</code> is a <em>response vector</em> <code>X</code> is a <em>matrix</em> of input variables and <code>b</code> is the vector of fit parameters I am searching for.</p>
  
  <p>Python provides <code>b = numpy.linalg.lstsq( X , y )</code> for solving problems of this form.</p>
  
  <p>However, when I use this I tend to get either extremely large or extremely small values for the components of <code>b</code>.</p>
  
  <p>I'd like to perform the same fit, but constrain the values of <code>b</code> between 0 and 255.</p>
  
  <p>It looks like <code>scipy.optimize.fmin_slsqp()</code> is an option, but I found it extremely slow for the size of problem I'm interested in (<code>X</code> is something like <code>3375 by 1500</code> and hopefully even larger).</p>
  
  <ol>
  <li>Are there any other Python options for performing constrained least
  squares fits?</li>
  <li>Or are there python routines for performing <a href="http://en.wikipedia.org/wiki/Least_squares#LASSO_method" rel="noreferrer">Lasso
  Regression</a> or Ridge Regression or some other regression method
  which penalizes large <code>b</code> coefficient values?</li>
  </ol>