Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import pandas as pd
- import matplotlib.pylab as plt
- import numpy as np
- # see also http://www.wired.com/wiredscience/2011/01/linear-regression-with-pylab/
- data = [
- (0.2, 1.3),
- (1.3, 3.9),
- (2.1, 4.8),
- (2.9,5.5),
- (3.3,6.9)
- ]
- df = pd.DataFrame(data, columns=['X', 'Y'])
- print(df)
- model_with_intercept = pd.ols(y=df['Y'], x=df['X'], intercept=True)
- df['Y_fit_with_intercept'] = model_with_intercept.y_fitted
- model_no_intercept = pd.ols(y=df['Y'], x=df['X'], intercept=False)
- df['Y_fit_no_intercept'] = model_no_intercept.y_fitted
- df.plot(x='X', y=['Y', 'Y_fit_with_intercept', 'Y_fit_no_intercept'])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement