I've a pandas series which contains the daily load consumption of a city for a year. I wish to forecast the load consumption for next year.As a result , I'm making use of exponential time series.

The problem is apart from statsmodels' SimpleExpSmoothing , ExponentialSmoothing and Holt I couldn't find any other library which does this.

I work in Google Colab which uses Python 3.7 and the only version of Statsmodel which is compatible with Python 3.7 is 0.10.2 which has a lot of issues.

As a result , I'd like to know if there any other libraries which accomplish this task. (I'm too lazy to code this from scratch).


1 Answer 1


You can code exponential smoothing in less than 10 lines:

class ExpSmooth:
    def __init__(self, a):
        assert 0 <= a <= 1
        self.a = a
        self.y_smooth = 0

    def smooth(self, Input):
        self.y_smooth = self.a * Input + (1 - self.a) * self.y_smooth
        return self.y_smooth

Then the smoothed values for each time step will be:

smoother = ExpSmooth(0.2)
smoothed = [smoother.smooth(y) for y in your_time_series]

You could probably use Pandas' apply method to apply smoother.smooth to each element of your time-series.

The Holt model adds one more smoothed state (so you'll have self.trend_smooth and self.nontrend_smooth) and a corresponding update equation. That should take about 10 quick and simple lines of code as well.

  • $\begingroup$ With just a couple more lines you can add the bias correction (keeping track of the product of all smoothing terms a used so far and dividing self.y_smooth by 1 - that product before returning, so that (if desired) the series doesn't start out with a default value of 0 $\endgroup$
    – jwimberley
    Commented Jan 27, 2022 at 14:27
  • $\begingroup$ This looks great , just one doubt: I've to forecast around 8000 values (all hours in a year) , but the above given code only computes 1 value , am I correct ? $\endgroup$
    – akshit.C
    Commented Jan 27, 2022 at 15:02
  • $\begingroup$ @akshit.C, the part of the answer that starts with "Then the smoothed values for each time step will be" explains how to apply smoothing to the full time-series. $\endgroup$
    – ForceBru
    Commented Jan 27, 2022 at 15:36

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.