Guest User

Untitled

a guest
Feb 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import numpy as np
  2. from matplotlib import pyplot as plt
  3.  
  4. def my_dist(x):
  5. return np.exp(-x ** 2)
  6.  
  7. x = np.arange(-100, 100)
  8. p = my_dist(x)
  9. plt.plot(x, p)
  10. plt.show()
  11.  
  12. import numpy as np
  13. from scipy.interpolate import UnivariateSpline
  14. from matplotlib import pyplot as plt
  15.  
  16. N = 1000
  17. n = N//10
  18. s = np.random.normal(size=N) # generate your data sample with N elements
  19. p, x = np.histogram(s, bins=n) # bin it into n = N//10 bins
  20. x = x[:-1] + (x[1] - x[0])/2 # convert bin edges to centers
  21. f = UnivariateSpline(x, p, s=n)
  22. plt.plot(x, f(x))
  23. plt.show()
  24.  
  25. from scipy.stats.kde import gaussian_kde
  26. from numpy import linspace
  27. # create fake data
  28. data = randn(1000)
  29. # this create the kernel, given an array it will estimate the probability over that values
  30. kde = gaussian_kde( data )
  31. # these are the values over wich your kernel will be evaluated
  32. dist_space = linspace( min(data), max(data), 100 )
  33. # plot the results
  34. plt.plot( dist_space, kde(dist_space) )
Add Comment
Please, Sign In to add comment