Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2.  
  3. u = [-2, 0, 2, 1, -1]
  4. y = [4, 6, 8, 7, 5]
  5.  
  6. def theta(u,y):
  7.     theta_licznik = 0
  8.     theta_mianownik = 0
  9.     for un, yn in zip(u,y):
  10.         theta_licznik+=(yn*un)
  11.         theta_mianownik+=un**2
  12.     return theta_licznik/theta_mianownik
  13.  
  14. plt.scatter(u,y)
  15. t = theta(u,y)
  16.  
  17. y2=[]
  18. for el in u:
  19.     y2.append(t*el)
  20.  
  21. u, y2 = (list(x) for x in zip(*sorted(zip(u, y2))))
  22.  
  23. plt.plot(u,y2)
  24. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement