hello - is there a rolling moving average method i...
# statsforecast
j
hello - is there a rolling moving average method in statsforecast?
j
Hey. Not at the moment, but it'll be in the next release of coreforecast (later this week)
♥️ 1
j
Excellent! Thank you @José Morales
j
There's one in window_ops though
j
window though produces a flat forecast ... just average the the last x observations.. its not 'moving' ..correct?
oh nvm.. window_ops is different than WindowAverage
j
ah, sorry. you mean a model
👍 1
I think that's what WindowAverage does, are you looking for something different?
j
what i think window average does.. is a naive forecast based on some average of x prior periods.. its not a 'recursive' method. I am looking for a moving average.. similar to exp smoothing, but equally weighted
j
I see. I shared an example here a while ago with mlforecast, let me see if I can find it
❤️ 1
I didn't find the message (it gets deleted and I don't remember the name of our archive) but here's the code:
Copy code
from mlforecast import MLForecast
from mlforecast.lag_transforms import RollingMean
from sklearn.base import BaseEstimator
from utilsforecast.data import generate_series

class WindowAverage(BaseEstimator):
    def __init__(self, window_size):
        self.window_size = window_size

    def fit(self, X, y):
        return self

    def predict(self, X):
        return X[f'rolling_mean_lag1_window_size{self.window_size}']

freq = 'H'
window_size = 13
horizon = 2 * window_size
data = generate_series(1, freq=freq)
fcst = MLForecast(
    models=[WindowAverage(window_size)],
    freq=freq,
    lag_transforms={1: [RollingMean(window_size)]}
)
fcst.fit(data)
fcst.predict(horizon)
Please let us know if this doesn't work out for you
j
thank you Jose, i will try this out.