• API
• FAQ
• Tools
• Archive
SHARE
TWEET # Untitled a guest Jul 18th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import matplotlib.pyplot as plt
2. import numpy as np
3. import random
4.
5. np.random.rand()
6.
7. m = 0
8. b = 0
9. l = 0.0001
10.
11.
12. x = []
13. y = []
14.
15. with open('/home/idstudent/.PyCharmCE2019.1/config/scratches/scratch.txt' , 'r') as infile:
16.     for line in infile:
17.
18.         b = line.split(',')
19.         x.append(float(b.strip()))
20.         y.append(float(b.strip()))
21.
22. normx = []
23. normy = []
24.
25. for i in range(0,len(x)):
26.     normx.append((x[i] - min(x)) / (max(x) - min(x)))
27.     normy.append((y[i] - min(y)) / (max(y) - min(y)))
28. b = 0
29. x = normx
30. y = normy
31. print(x)
32. n = len(x)
33.
34. for j in range(0,1000000):
35.     dm = 0
36.     db = 0
37.     for i in range(0, len(x)):
38.         yHat = m * x[i] + b
39.         dm += (-2 / n) * x[i] * (y[i] - yHat)
40.         db += (-2 / n) * (y[i] - yHat)
41.
42.     m = m - l * dm
43.     b = b - l * db
44. newX = [0,1]
45. newY = [b, m + b]
46.
47. plt.plot(newX, newY, '--')
48. plt.plot(x, y, 'ro')
49. plt.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.
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!

Top