With the following code I can find the best forecast value for a series by iterating over the alpha, beta and gamma and saving the result with the best RMSE:

model = sm.tsa.ExponentialSmoothing(demands['demand'], trend='add', seasonal='add')
bestError = None
result = None

for alpha in np.arange(0, 1.01, 0.01):
    for beta in np.arange(0, 1.01, 0.01):
        for gamma in np.arange(0, 1.01, 0.01):
            fittedModel = model.fit(smoothing_level=alpha, smoothing_trend=beta, smoothing_seasonal=gamma)

            error = sm.tools.eval_measures.rmse(fittedModel.fittedvalues.tail(12), demands.demand.tail(12))

            if bestError is None or error < bestError:
                bestError = error
                result = fittedModel.forecast(steps=3)

However the code above has the downside that it may take up to 2 hours to generate the best forecast for a single item.

Is there a way to deduce or calculate what would be the best alpha, beta and gamma without iterating over all possible combinations?

Do note that this is going to used for hundreds of items, so manual inspection of each item is not feasible.


1 Answer 1


Instead of doing a grid search over all possible models, we can directly find the model with the lowest MSE by optimization (i.e. maximum likelihood).

If you assume the following model:

$$ y_{t} | l_{t-1}, b_{t-1}, s_{t-m}, \sigma^2 \sim \text{Normal}(\mu=l_{t-1} + b_{t-1} + s_{t-m}, \sigma^2),\\ l_{t} = l_{t-1} + b_{t-1} + \alpha\epsilon_{t}, \\ b_{t} = b_{t-1} + \beta\epsilon_{t}, \\ s_{t} = s_{t-m} + \gamma\epsilon_{t} $$

where $\epsilon_{t} = y_{t} - l_{t-1} - b_{t-1} - s_{t-m} \sim \text{Normal}(0, \sigma^2)$.

Then you can find the values $\alpha$, $\beta$, and $\gamma$ that directly minimize MSE (i.e. maximum likelihood assuming the model above).

In your case, the optimal parameters can be found by running:

 fittedModel = model.fit()

The key is a default argument called optimized. In the documentation, the parameters you are setting as constant are optional arguments - leaving them as None and setting optimized=True (which is the default) will find the optimal $\alpha$, $\beta$, and $\gamma$ for you by minimizing the mean squared error.

  • 1
    $\begingroup$ Yep, turns out the most effective way is to trust the library. Thank you! $\endgroup$ Commented Jan 31 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.