find the best k for moving average forecasting algorithm
In [171: import numpy as np import matplotlib.pyplot as plt x = np . array( [820,775,680,655,750,802,798,689,775] ) def mov_avg(x,k): np . full(x.size , np.nan) cast for t in range(k,x.size): forecastit] np.mean (x(t-k:t]) return forecast def weightedhttp://1ocalhost:8888/notebooks/Untitled. ipynb2kernel_name-pyt hon 3 #-mov-avg ( x , w ) : rnel name kw.size forecast np.full (x.size, np.nan) for t in range(k,x.size): forecast[t] np . sum ( x [ t-k:t)”w) = return forecast def exp
OR
OR