Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Sat Sep 21 08:26:54 2019
  5.  
  6. @author: FranChan
  7. """
  8. import matplotlib.pyplot, pylab
  9. from copy import deepcopy
  10. prices = []
  11. prices.append([40,50000])
  12. prices.append([52,72000])
  13. prices.append([85,120000])
  14. prices.append([120,180000])
  15. pprices = []
  16. for p in prices:
  17.     pp = deepcopy(p)
  18.     pp.append(p[0]*p[1])
  19.     pp.append(p[0]**2)
  20.     pp.append(p[1]**2)
  21.     pprices.append(pp)
  22. sy = 0
  23. sx = 0
  24. sy2 = 0
  25. sx2 = 0
  26. sxy = 0
  27. for p in pprices:
  28.     sy+=p[1]
  29.     sx+=p[0]
  30.     sxy+=p[2]
  31.     sx2+=p[3]
  32.     sy2+=p[4]
  33. n = len(prices)
  34. print(sx,sy,sxy,sx2,sy2)
  35. a = (sy*sx2-sx*sxy)/(n*sx2-(sx**2))
  36. b = (n*(sxy)-sx*sy)/(n*sx2-(sx**2))
  37. print(a,b)
  38. prediction = []
  39. for p in pprices:
  40.     prediction.append([p[0],b*p[0]+a])
  41. c = int(input("How many x would you like to enter"))
  42. xinp = []
  43. for i in range(c):
  44.     nx = int(input("Enter x: "))
  45.     xinp.append([nx,b*nx+a])
  46. matplotlib.pyplot.scatter(*zip(*prices))
  47. matplotlib.pyplot.plot(*zip(*prediction))
  48. matplotlib.pyplot.scatter(*zip(*xinp))
  49. matplotlib.pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement