Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)

Untitled

By: Femto_Trader on Oct 1st, 2012  |  syntax: Python  |  size: 0.65 KB  |  hits: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2.  
  3. import pandas as pd
  4. import matplotlib.pylab as plt
  5. import numpy as np
  6.  
  7. # see also http://www.wired.com/wiredscience/2011/01/linear-regression-with-pylab/
  8.  
  9. data = [
  10. (0.2, 1.3),
  11. (1.3, 3.9),
  12. (2.1, 4.8),
  13. (2.9,5.5),
  14. (3.3,6.9)
  15. ]
  16.  
  17. df = pd.DataFrame(data, columns=['X', 'Y'])
  18.  
  19. print(df)
  20.  
  21. model_with_intercept = pd.ols(y=df['Y'], x=df['X'], intercept=True)
  22. df['Y_fit_with_intercept'] = model_with_intercept.y_fitted
  23.  
  24. model_no_intercept = pd.ols(y=df['Y'], x=df['X'], intercept=False)
  25. df['Y_fit_no_intercept'] = model_no_intercept.y_fitted
  26.  
  27. df.plot(x='X', y=['Y', 'Y_fit_with_intercept', 'Y_fit_no_intercept'])
  28.  
  29. plt.show()