SHARE
TWEET

Untitled

a guest Sep 21st, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top