Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Sat Sep 21 08:26:54 2019
- @author: FranChan
- """
- import matplotlib.pyplot, pylab
- from copy import deepcopy
- prices = []
- prices.append([40,50000])
- prices.append([52,72000])
- prices.append([85,120000])
- prices.append([120,180000])
- pprices = []
- for p in prices:
- pp = deepcopy(p)
- pp.append(p[0]*p[1])
- pp.append(p[0]**2)
- pp.append(p[1]**2)
- pprices.append(pp)
- sy = 0
- sx = 0
- sy2 = 0
- sx2 = 0
- sxy = 0
- for p in pprices:
- sy+=p[1]
- sx+=p[0]
- sxy+=p[2]
- sx2+=p[3]
- sy2+=p[4]
- n = len(prices)
- print(sx,sy,sxy,sx2,sy2)
- a = (sy*sx2-sx*sxy)/(n*sx2-(sx**2))
- b = (n*(sxy)-sx*sy)/(n*sx2-(sx**2))
- print(a,b)
- prediction = []
- for p in pprices:
- prediction.append([p[0],b*p[0]+a])
- c = int(input("How many x would you like to enter"))
- xinp = []
- for i in range(c):
- nx = int(input("Enter x: "))
- xinp.append([nx,b*nx+a])
- matplotlib.pyplot.scatter(*zip(*prices))
- matplotlib.pyplot.plot(*zip(*prediction))
- matplotlib.pyplot.scatter(*zip(*xinp))
- matplotlib.pyplot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement