SHARE
TWEET

Untitled

a guest Apr 21st, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import matplotlib.pyplot as pl
  3. import numpy as np
  4.  
  5. A = 1.
  6. B = 0.5
  7. sigma = 0.3
  8. xmax = 4.
  9. numberOfClassEl = 200
  10. data = []
  11. sumx =0
  12. sumg = 0
  13. sumxg =0
  14. sumxx =0
  15. for rowNum in range(numberOfClassEl):
  16.     X = random.random()*xmax
  17.     sumx = sumx + X
  18.     G = A+B*X+random.gauss(0,sigma)
  19.     sumg = sumg + G
  20.     sumxg = X*G + sumxg
  21.     sumxx = X*X + sumxx
  22.     data.append([X, G])
  23.  
  24. b = (sumxg/200 - sumx/200*sumg/200)/(sumxx/200 - (sumx/200)**2)
  25. a = -b*sumx/200 + sumx/200
  26. print(a, b)
  27.  
  28. f = np.linspace(0, 4, 200)
  29. pl.plot(f, a+b*f)
  30.  
  31. pl.scatter([data[i][0] for i in range(len(data))],[data[i][1] for i in range(len(data))],)
  32. pl.savefig('genLRdata.png')
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