A shop wants a forecast of tomorrow's sales that follows recent days without jumping at every blip. Simple exponential smoothing keeps one number, the level, and moves it part of the way toward each new observation.
Implement two functions.
ses(series, alpha)
series is a list of numbers and alpha is the smoothing weight, .
Return a dict with:
"levels": the list "forecast": the forecast for the next, unseen period, which is "sse": the sum of squared one-step errors, Round every number to 4 decimals.
best_alpha(series, alphas)
alphas is a non-empty list of candidate weights. Return the one whose ses(series, alpha)["sse"] is smallest. If several tie, return the one that comes first in alphas.
levels has one entry, forecast equals it and sse is 0.0.