Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Oct 5 09:12:57 2019
  4.  
  5. @author: CS41FC1
  6. """
  7.  
  8. import matplotlib.pyplot as plt
  9. import numpy as np
  10. import math
  11.  
  12. e = 2.71828182846
  13.  
  14. #x value
  15. #cost = [20000, 40000, 60000, 80000, 100000, 120000, 140000, 160000]
  16. #cost = [1,2,3,4,5,6,7,8]
  17. cost = [4.2, 5.1, 5.5, 8.2, 9, 9.1]
  18.  
  19.  
  20.  
  21. #y value
  22. result = [0,0,0,1,1,1]
  23. #predict result when 50000 is added
  24.  
  25. xi =sum(cost)/len(cost)
  26. yi =sum(result)/len(result)
  27.  
  28.  
  29. #z = (x-xi)
  30. a=[]
  31. for i in cost:
  32. a.append(i-xi)
  33.  
  34.  
  35. #w = (y-yi)
  36. b=[]
  37. for i in result:
  38. bsub=float(i-yi)
  39. b.append(bsub)
  40.  
  41. c =[]
  42. for i in a:
  43. csub=float(i*i)
  44. c.append(csub)
  45.  
  46.  
  47. product = []
  48. for i in range(len(cost)):
  49. mult=b[i]*a[i]
  50. product.append(mult)
  51.  
  52.  
  53. cSum=(sum(c))
  54. productSum =(sum(product))
  55.  
  56. m = productSum/cSum
  57. c = yi-(m*xi)
  58.  
  59.  
  60. val = []
  61.  
  62. for i in cost:
  63. val.append(i)
  64.  
  65. data = float(input("Enter a number: "))
  66. val.append(data)
  67. val.sort()
  68.  
  69.  
  70. linearRegY=[]
  71. for i in val:
  72. ysub= m*i+c
  73. linearRegY.append(ysub)
  74.  
  75.  
  76. print("Output: \t\t\t Linear Regression ")
  77.  
  78. for i in range (len(val)):
  79. print(str(val[i])+"\t\t\t\t"+str(linearRegY[i]))
  80.  
  81.  
  82.  
  83. p = []
  84. for i in linearRegY:
  85. x = 1 / (1+(math.exp(-i) ))
  86. p.append(x)
  87.  
  88. p2 = []
  89. for i in p:
  90. p2.append(i/ (1-i))
  91.  
  92. newY =[]
  93. for i in p2:
  94. newY.append( np.log(i) )
  95.  
  96. xV = [1,2,3,4,5,6,7]
  97.  
  98.  
  99. plotY = []
  100. for i in newY:
  101. if i > .5:
  102. plotY.append("passed")
  103. else:
  104. plotY.append("failed")
  105.  
  106.  
  107. plt.plot(xV,newY, 'ro-')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement