title: how does sklearn do Linear regression when p >n?
body: <p>it's known that when the number of variables (p) is larger than the number of samples (n) the least square estimator is not defined.</p>
  
  <p>In sklearn I receive this values:</p>
  
  <pre><code>In [30]: lm = LinearRegression().fit(xx,y_train)
  
  In [31]: lm.coef_
  Out[31]: 
  array([[ 0.20092363, -0.14378298, -0.33504391, ..., -0.40695124,
           0.08619906, -0.08108713]])
  
  In [32]: xx.shape
  Out[32]: (1097, 3419)
  </code></pre>
  
  <p>Call [30] should return an error. How does sklearn work when p>n like in this case?</p>
  
  <p>EDIT:
  It seems that the matrix is filled with some values </p>
  
  <pre><code>if n &gt; m:
          # need to extend b matrix as it will be filled with
          # a larger solution matrix
          if len(b1.shape) == 2:
              b2 = np.zeros((n, nrhs), dtype=gelss.dtype)
              b2[:m,:] = b1
          else:
              b2 = np.zeros(n, dtype=gelss.dtype)
              b2[:m] = b1
          b1 = b2
  </code></pre>