17

I am working on time series in python. The libraries which I found useful and promising are

  • pandas;
  • statsmodel (for ARIMA);
  • simple exponential smoothing is provided from pandas.

Also for visualization: matplotlib

Does anyone know a library for exponential smoothing?

foc
  • 947
  • 1
  • 9
  • 26

3 Answers3

24

Pandas has exponentially weighted moving moment functions

http://pandas.pydata.org/pandas-docs/dev/computation.html?highlight=exponential#exponentially-weighted-moment-functions

By the way, there shouldn't be any functionality leftover in the scikits.timeseries package that is not also in pandas.

Edit: Since this is still a popular question, there is now a work in progress pull request to add more fully featured exponential smoothing to statsmodels here

jseabold
  • 7,903
  • 2
  • 39
  • 53
8

Somehow some questions got merged or deleted, so I'll post my answer here.

Exp smoothing in Python natively.

'''
simple exponential smoothing
go back to last N values
y_t = a * y_t + a * (1-a)^1 * y_t-1 + a * (1-a)^2 * y_t-2 + ... + a*(1-a)^n * y_t-n
'''
from random import random,randint

def gen_weights(a,N):
    ws = list()
    for i in range(N):
        w = a * ((1-a)**i)
        ws.append(w)
    return ws

def weighted(data,ws):
    wt = list()
    for i,x in enumerate(data):
        wt.append(x*ws[i])
    return wt

N = 10
a = 0.5
ws = gen_weights(a,N)
data = [randint(0,100) for r in xrange(N)]
weighted_data = weighted(data,ws)
print 'data: ',data
print 'weights: ',ws
print 'weighted data: ',weighted_data
print 'weighted avg: ',sum(weighted_data)
RParadox
  • 6,393
  • 4
  • 23
  • 33
6

you can predict the future values using Pandas Exponentially-weighted moving average http://pandas.pydata.org/pandas-docs/stable/generated/pandas.stats.moments.ewma.html as

from pandas.stats.moments import ewma
import numpy as np

pred_period = 12

def predict(x,span,periods = pred_period):     
    x_predict = np.zeros((span+periods,))
    x_predict[:span] = x[-span:]
    pred =  ewma(x_predict,span)[span:]

    return pred
Chitrasen
  • 1,706
  • 18
  • 15