Skip to main content

Fast univariate time series models that run in Pyodide

Project description

skaters

Fast univariate online time series models. Zero dependencies. Runs in Pyodide.

Install

pip install skaters

Quick start

from skaters import ensemble, envelope

# Create a precision-weighted ensemble of EMA models
f = ensemble(k=3)  # predict 3 steps ahead

state = None
for y in observations:
    x, state = f(y, state)
    # x = [float, float, float]  (forecasts for horizons 1, 2, 3)

# Want uncertainty bands? Wrap any skater with an envelope:
f = envelope(ensemble(k=3), k=3)

state = None
for y in observations:
    out, state = f(y, state)
    # out["mean"] = point forecasts
    # out["std"]  = empirical std of forecast error per horizon

The skater convention

A skater is any callable with this signature:

x, state = f(y, state)
Argument Type Description
y float New observation
state dict | None Prior state (None on first call)
Returns
x list[float] Point forecasts for horizons 1..k
state dict Updated state (pass back next call)

Skaters only predict. Uncertainty is handled separately by the envelope.

Built-in skaters

EMA

Exponential moving average. O(1) per observation.

from skaters import ema

f = ema(alpha=0.1, k=1)

Convenience constructors

Pre-configured EMA speeds:

from skaters import rapidly, quickly, slowly, sluggishly

f = rapidly(k=1)     # alpha=0.3
f = quickly(k=1)     # alpha=0.1
f = slowly(k=1)      # alpha=0.05
f = sluggishly(k=1)  # alpha=0.01

Precision-weighted ensemble

Combines multiple skaters, weighting each by 1/MSE of its forecast errors. Automatically favors models that are both accurate and unbiased.

from skaters import ensemble, precision_weighted_ensemble, ema

# Default: ensemble of EMAs at different speeds
f = ensemble(k=3)

# Custom: bring your own skaters
f = precision_weighted_ensemble(
    skaters=[ema(alpha=0.05, k=3), ema(alpha=0.2, k=3)],
    k=3,
)

Envelope

The envelope wraps any skater and tracks empirical forecast errors at each horizon. It is model-independent — it doesn't care how the predictions are made.

from skaters import envelope, ema

# Welford's (uniform weight over all history)
f = envelope(ema(alpha=0.1, k=3), k=3)

# Exponentially weighted (forgets old errors, adapts to regime changes)
f = envelope(ema(alpha=0.1, k=3), k=3, decay=0.95)

state = None
for y in observations:
    out, state = f(y, state)
    print(out["mean"], out["std"])

Writing your own skater

Any function matching the convention works:

def my_skater(y: float, state: dict | None) -> tuple[list[float], dict]:
    if state is None:
        state = {"last": y}
    state["last"] = y
    return [state["last"]], state  # predict last value for k=1

# Use it standalone or in an ensemble:
from skaters import envelope, precision_weighted_ensemble

f = envelope(my_skater, k=1)
f = precision_weighted_ensemble([my_skater, ema(alpha=0.1, k=1)], k=1)

Design

  • Online only — O(1) per observation, no batch recomputation
  • Prediction and uncertainty are separate — skaters predict, envelopes estimate error
  • Pure Python — zero dependencies, runs anywhere Python runs
  • Pyodide compatible — works in the browser via WebAssembly

Lineage

This package distills ideas from timemachines, which provided a common skater interface for dozens of time series packages. This is a from-scratch rewrite focused on speed, simplicity, and browser compatibility.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skaters-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skaters-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file skaters-0.1.0.tar.gz.

File metadata

  • Download URL: skaters-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for skaters-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d45411545e40b0289e35c12d802185211f2abb861e2ae8d47463b0426f33de5f
MD5 b9a55dbcc8770cecd31a673eb5d0b92d
BLAKE2b-256 6fbc552d9fb0e7d29971f0b4b80e4832f3aef282a165b3bd9463c196dc8b1699

See more details on using hashes here.

File details

Details for the file skaters-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: skaters-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for skaters-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8a92431152b20d81a252346de63fb73dbdd40be652fcaa7fe5991b0ee997728
MD5 89ce97044fa3b09501f9f0eb9a747d90
BLAKE2b-256 70f2bf49e816e3ff9db93f101199ba26e8d67f21378c4036c5c9517dad59ab7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page