Advertisement
Femto_Trader

Untitled

Oct 1st, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement