furas

Python - Exponentially weighted moving average

Jun 24th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2.  
  3. # Exponentially weighted moving average
  4. # https://medium.com/@abhinav.mahapatra10/beginners-ml-basics-exponentially-weighted-moving-average-8ce3e75768f6
  5.  
  6. data1 = [25, 28, 26, 22, 19, 23, 27]
  7. data2 = []
  8.  
  9. a = 0.2
  10. b = 1-a
  11.  
  12. s = data1[0]
  13. data2.append(s)
  14.  
  15. for x in data[1:]:
  16.     s = a*x + b*s
  17.     data2.append(s)
  18.    
  19. plt.plot(data1)
  20. plt.plot(data2)
  21.  
  22. plt.show()
Add Comment
Please, Sign In to add comment