Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Sat Oct 5 09:12:57 2019
- @author: CS41FC1
- """
- import matplotlib.pyplot as plt
- import numpy as np
- import math
- e = 2.71828182846
- #x value
- #cost = [20000, 40000, 60000, 80000, 100000, 120000, 140000, 160000]
- #cost = [1,2,3,4,5,6,7,8]
- cost = [4.2, 5.1, 5.5, 8.2, 9, 9.1]
- #y value
- result = [0,0,0,1,1,1]
- #predict result when 50000 is added
- xi =sum(cost)/len(cost)
- yi =sum(result)/len(result)
- #z = (x-xi)
- a=[]
- for i in cost:
- a.append(i-xi)
- #w = (y-yi)
- b=[]
- for i in result:
- bsub=float(i-yi)
- b.append(bsub)
- c =[]
- for i in a:
- csub=float(i*i)
- c.append(csub)
- product = []
- for i in range(len(cost)):
- mult=b[i]*a[i]
- product.append(mult)
- cSum=(sum(c))
- productSum =(sum(product))
- m = productSum/cSum
- c = yi-(m*xi)
- val = []
- for i in cost:
- val.append(i)
- data = float(input("Enter a number: "))
- val.append(data)
- val.sort()
- linearRegY=[]
- for i in val:
- ysub= m*i+c
- linearRegY.append(ysub)
- print("Output: \t\t\t Linear Regression ")
- for i in range (len(val)):
- print(str(val[i])+"\t\t\t\t"+str(linearRegY[i]))
- p = []
- for i in linearRegY:
- x = 1 / (1+(math.exp(-i) ))
- p.append(x)
- p2 = []
- for i in p:
- p2.append(i/ (1-i))
- newY =[]
- for i in p2:
- newY.append( np.log(i) )
- xV = [1,2,3,4,5,6,7]
- plotY = []
- for i in newY:
- if i > .5:
- plotY.append("passed")
- else:
- plotY.append("failed")
- plt.plot(xV,newY, 'ro-')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement