Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. In [1]: import numpy as np
  2. ...: import pandas as pd
  3. ...: import seaborn as sns
  4. ...: import matplotlib.pyplot as plt
  5. ...: import statsmodels.formula.api as sfa
  6. ...:
  7.  
  8. In [2]: %matplotlib inline
  9. In [3]: np.random.seed(2016)
  10. In [4]: x = np.linspace(0, 10, 32)
  11. In [5]: y = 0.3 * x + np.random.randn(len(x))
  12. In [6]: df = pd.DataFrame({'x': x, 'y': y})
  13. In [7]: r = sfa.ols('y ~ x + 0', data=df).fit()
  14. In [8]: sns.lmplot(x='x', y='y', data=df, fit_reg=True)
  15. Out[8]: <seaborn.axisgrid.FacetGrid at 0xac88a20>
  16.  
  17. In [9]: fig, ax = plt.subplots(figsize=(5, 5))
  18. ...: ax.scatter(x=x, y=y)
  19. ...: ax.plot(x, r.fittedvalues)
  20. ...:
  21. Out[9]: [<matplotlib.lines.Line2D at 0x5675a20>]
  22.  
  23. sns.lmplot(x='x', y='y', data=df, fit_reg=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement