title: Adding scikit-learn (sklearn) prediction to pandas data frame
body: <p>I am trying to add a sklearn prediction to a pandas dataframe, so that I can make a thorough evaluation of the prediction. The relavant piece of code is the following:</p>
  
  <pre><code>clf = linear_model.LinearRegression()
  clf.fit(Xtrain,ytrain)
  ypred = pd.DataFrame({'pred_lin_regr': pd.Series(clf.predict(Xtest))})
  </code></pre>
  
  <p>The dataframes look like this:</p>
  
  <p><strong>Xtest</strong></p>
  
  <pre><code>       axial_MET  cos_theta_r1  deltaE_abs  lep1_eta   lep1_pT  lep2_eta  
  8000   1.383026      0.332365    1.061852  0.184027  0.621598 -0.316297   
  8001  -1.054412      0.046317    1.461788 -1.141486  0.488133  1.011445   
  8002   0.259077      0.429920    0.769219  0.631206  0.353469  1.027781   
  8003  -0.096647      0.066200    0.411222 -0.867441  0.856115 -1.357888   
  8004   0.145412      0.371409    1.111035  1.374081  0.485231  0.900024   
  </code></pre>
  
  <p><strong>ytest</strong></p>
  
  <pre><code>8000    1
  8001    0
  8002    0
  8003    0
  8004    0
  </code></pre>
  
  <p><strong>ypred</strong></p>
  
  <pre><code>        pred_lin_regr
  0       0.461636
  1       0.314448
  2       0.363751
  3       0.291858
  4       0.416056
  </code></pre>
  
  <p>Concatenating Xtest and ytest works fine:</p>
  
  <pre><code>df_total = pd.concat([Xtest, ytest], axis=1)
  </code></pre>
  
  <p>but the event information is lost on ypred.</p>
  
  <p>What would be the must python/pandas/numpy-like way to do this?</p>
  
  <p>I am using the following versions:</p>
  
  <pre><code>argparse==1.2.1
  cycler==0.9.0
  decorator==4.0.4
  ipython==4.0.0
  ipython-genutils==0.1.0
  matplotlib==1.5.0
  nose==1.3.7
  numpy==1.10.1
  pandas==0.17.0
  path.py==8.1.2
  pexpect==4.0.1
  pickleshare==0.5
  ptyprocess==0.5
  py==1.4.30
  pyparsing==2.0.5
  pytest==2.8.2
  python-dateutil==2.4.2
  pytz==2015.7
  scikit-learn==0.16.1
  scipy==0.16.1
  simplegeneric==0.8.1
  six==1.10.0
  sklearn==0.0
  traitlets==4.0.0
  wsgiref==0.1.2
  </code></pre>
  
  <p>I tried the following:</p>
  
  <pre><code>df_total["pred_lin_regr"] = clf.predict(Xtest) 
  </code></pre>
  
  <p>seems to do the job, but I think I can't be sure that the events are matched correctly</p>