Package for time series analysis in python [closed]
Asked Answered
E

3

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?

Elimination answered 4/10, 2012 at 11:38 Comment(0)
S
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

Slattern answered 4/10, 2012 at 13:4 Comment(1)
thank you very much for the update and for the good work.Elimination
C
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)
Celestinecelestite answered 25/10, 2012 at 14:5 Comment(0)
D
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
Diannadianne answered 13/2, 2014 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.