title: How can I increase speed/performance with Scikit-learn regression and Pandas?
body: <p>I am playing with the excellent Scikit-learn today.  I'm forming the x's out of panels sliced on the minor_axis and y's out of DataFrame sliced on columns.  At the moment I'm doing endless iterations, does any .apply() Masters out there have any idea how to speed this up ? </p>
  
  <pre><code>from pandas import *
  import numpy as np
  from sklearn import linear_model
  np.random.seed(247)
  x = Panel(np.random.rand(3,25,10))
  y = y = DataFrame(np.random.rand(25,5))
  r2 = Series(index=y.columns)
  for i in y.columns:
      X = x.ix[:,:,i]
      Y = y.ix[:,i]
      r2.ix[i] = linear_model.LinearRegression().fit(X,Y).score(X,Y)
  
  In [325]: r2
  Out[325]: 
  0    0.061945
  1    0.091734
  2    0.004635
  3    0.015835
  4    0.027906
  dtype: float64
  </code></pre>
  
  <p>My idea was to apply this function (or similar) column wise. Have played with .apply() but because its a double(or triple) function call i.e. f1.().f2(x,y) or f1.().f2(x,y).f3(x,y) it gives me an error.  Any ideas would be greatly appreciated and I think this would be a very useful bit of code to have out there!
  LW</p>