Skip to main content

Time-series machine learning at scale.

Project description

Time-series machine learning at scale


functime Python PyPi uv Code style: black GitHub Run Quickstart Discord


functime is a powerful Python library for production-ready global forecasting and time-series feature extraction on large panel datasets.

functime also comes with time-series preprocessing (box-cox, differencing etc), cross-validation splitters (expanding and sliding window), and forecast metrics (MASE, SMAPE etc). All optimized as lazy Polars transforms.

Join us on Discord!

Highlights

  • Fast: Forecast and extract features (e.g. tsfresh, Catch22) across 100,000 time series in seconds on your laptop
  • Efficient: Embarrassingly parallel feature engineering for time-series using Polars
  • Battle-tested: Machine learning algorithms that deliver real business impact and win competitions
  • Exogenous features: supported by every forecaster
  • Backtesting with expanding window and sliding window splitters
  • Automated lags and hyperparameter tuning using FLAML

Additional Highlights

functime comes with a specialized LLM agent to analyze, describe, and compare your forecasts. Check out the walkthrough here.

Getting Started

Install functime using uv (recommended) or pip:

# Using uv (recommended)
uv add functime

# Or using pip
pip install functime

functime comes with extra options. For example, to install functime with large-language model (LLM) and lightgbm features:

# Using uv (recommended)
uv add "functime[llm,lgb]"

# Or using pip
pip install "functime[llm,lgb]"
  • cat: To use catboost forecaster
  • xgb: To use xgboost forecaster
  • lgb: To use lightgbm forecaster
  • llm: To use the LLM-powered forecast analyst

Forecasting

import polars as pl
from functime.cross_validation import train_test_split
from functime.seasonality import add_fourier_terms
from functime.forecasting import linear_model
from functime.preprocessing import scale
from functime.metrics import mase

# Load commodities price data
y = pl.read_parquet("https://github.com/functime-org/functime/raw/main/data/commodities.parquet")
entity_col, time_col = y.columns[:2]

# Time series split
y_train, y_test = y.pipe(train_test_split(test_size=3))

# Fit-predict
forecaster = linear_model(freq="1mo", lags=24)
forecaster.fit(y=y_train)
y_pred = forecaster.predict(fh=3)

# functime ❤️ functional design
# fit-predict in a single line
y_pred = linear_model(freq="1mo", lags=24)(y=y_train, fh=3)

# Score forecasts in parallel
scores = mase(y_true=y_test, y_pred=y_pred, y_train=y_train)

# Forecast with target transforms and feature transforms
forecaster = linear_model(
    freq="1mo",
    lags=24,
    target_transform=scale(),
    feature_transform=add_fourier_terms(sp=12, K=6)
)

# Forecast with exogenous regressors!
# Just pass them into X
X = (
    y.select([entity_col, time_col])
    .pipe(add_fourier_terms(sp=12, K=6)).collect()
)
X_train, X_future = y.pipe(train_test_split(test_size=3))
forecaster = linear_model(freq="1mo", lags=24)
forecaster.fit(y=y_train, X=X_train)
y_pred = forecaster.predict(fh=3, X=X_future)

View the full walkthrough on forecasting here.

Feature Extraction

functime comes with over 100+ time-series feature extractors. Every feature is easily accessible via functime's custom ts (time-series) namespace, which works with any Polars Series or expression. To register the custom ts Polars namespace, you must first import functime in your module.

To register the custom ts Polars namespace, you must first import functime!

import polars as pl
import numpy as np
from functime.feature_extractors import FeatureExtractor, binned_entropy

# Load commodities price data
y = pl.read_parquet("https://github.com/functime-org/functime/raw/main/data/commodities.parquet")

# Get column names ("commodity_type", "time", "price")
entity_col, time_col, value_col = y.columns

# Extract a single feature from a single time-series
binned_entropy = binned_entropy(
    pl.Series(np.random.normal(0, 1, size=10)),
    bin_count=10
)

# 🔥 Also works on LazyFrames with query optimization
features = (
    pl.LazyFrame({
        "index": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        "value": np.random.normal(0, 1, size=10)
    })
    .select(
        binned_entropy=pl.col("value").ts.binned_entropy(bin_count=10),
        lempel_ziv_complexity=pl.col("value").ts.lempel_ziv_complexity(threshold=3),
        longest_streak_above_mean=pl.col("value").ts.longest_streak_above_mean(),
    )
    .collect()
)

# 🚄 Extract features blazingly fast on many
# stacked time-series using `group_by`
features = (
    y.group_by(entity_col)
    .agg(
        binned_entropy=pl.col(value_col).ts.binned_entropy(bin_count=10),
        lempel_ziv_complexity=pl.col(value_col).ts.lempel_ziv_complexity(threshold=3),
        longest_streak_above_mean=pl.col(value_col).ts.longest_streak_above_mean(),
    )
)

# 🚄 Extract features blazingly fast on windows
# of many time-series using `group_by_dynamic`
features = (
    # Compute rolling features at yearly intervals
    y.group_by_dynamic(
        time_col,
        every="12mo",
        group_by=entity_col,
    )
    .agg(
        binned_entropy=pl.col(value_col).ts.binned_entropy(bin_count=10),
        lempel_ziv_complexity=pl.col(value_col).ts.lempel_ziv_complexity(threshold=3),
        longest_streak_above_mean=pl.col(value_col).ts.longest_streak_above_mean(),
    )
)

Related Projects

If you are interested in general data-science related plugins for Polars, you must check out polars-ds. polars-ds is a project created by one of functime's core maintainers and is the easiest way to extend your Polars pipelines with commonly used data-science operations made blazing fast with Rust!

License

functime is distributed under Apache-2.0.

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

functime-1.0.0rc1.tar.gz (313.8 kB view details)

Uploaded Source

Built Distributions

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

functime-1.0.0rc1-cp311-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.11+Windows x86-64

functime-1.0.0rc1-cp311-abi3-win32.whl (3.9 MB view details)

Uploaded CPython 3.11+Windows x86

functime-1.0.0rc1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

functime-1.0.0rc1-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (5.9 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ i686

functime-1.0.0rc1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

functime-1.0.0rc1-cp311-abi3-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

functime-1.0.0rc1-cp311-abi3-macosx_10_12_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file functime-1.0.0rc1.tar.gz.

File metadata

  • Download URL: functime-1.0.0rc1.tar.gz
  • Upload date:
  • Size: 313.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for functime-1.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 86647f1ccf8eed01db2549e71b0bdada24367d3cbbe1faa22f8ca91c1cc3e644
MD5 5a509dc1b05f8a0774916888aecb5e2f
BLAKE2b-256 d31dae8d853505c35b82798a5412543b0b024c57f037232431e99212ed551d4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1.tar.gz:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: functime-1.0.0rc1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3e00bc2259a99f9a44640010aa5d8a7f4b2ef85b66378ca22589994690fbfb9d
MD5 8cca97b4d5d8b852967bc1af09027a3d
BLAKE2b-256 70849455ced9537247744dd1759af6a5bf73e24bf837f991f54e92cac2359517

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-win_amd64.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-win32.whl.

File metadata

  • Download URL: functime-1.0.0rc1-cp311-abi3-win32.whl
  • Upload date:
  • Size: 3.9 MB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 7aafd235a64543e97c64980103567b95906cb6441a8f9f521b161f38b1c93d1b
MD5 a15dd1a814fdaf2176b176cca8e97175
BLAKE2b-256 aa83e19cb1715a6d94b516214b0077ddfc2fdee408fb72b12915b6e6d9b60649

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-win32.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92800374047ec052a2c805299b71ba06a2b55dc5552177c5751ea31ca282cda9
MD5 3aa745998e73f241a28ee6ae61b9095a
BLAKE2b-256 6d018b9834209234cd7231698dae8bbaca82c8116254bbb444912a73bba33f5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 68eb81e8fc66601d11119ced3c48bf5e4ca05305dfd3facaa35f160dc5b953f5
MD5 679d15a18e2af99ca537646b29ec8b93
BLAKE2b-256 dc3c5469ded5ce0013eddba87f9f8b09fa4ffb3e97e43e978a7eae056fa07fdb

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 80591f2ace0da8a26b76b25b7a16d79c2dbd8eaf8361bf8042b8468cb87ab2cd
MD5 87795db283b61d24a39d0e1f38f6876f
BLAKE2b-256 29444db0970ecac5b713358320b5792354cea88e07f2747920acb2ce6aaf3004

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e75c7d097c048f766e614e8c1a48bc81698f4efd7e8f730fcb1b90215d4c2783
MD5 1cb8990626a3dc0a79311dfe2edba327
BLAKE2b-256 f1ab6ebe0d0808110ca48b144157bcb08884e6adb9408e2e439c63a14c092fa4

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file functime-1.0.0rc1-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for functime-1.0.0rc1-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0e32029897347b57bdbd696c8d4bf568695ecf95ec1396f1f593d1f09ac5eeb5
MD5 1dbed94a1a795eb8c0fca26d5eb6e412
BLAKE2b-256 c55c74b25dea7b8075fbd843df89084437dab655ea94ef4a24f872bb6136889e

See more details on using hashes here.

Provenance

The following attestation bundles were made for functime-1.0.0rc1-cp311-abi3-macosx_10_12_x86_64.whl:

Publisher: publish.yml on functime-org/functime

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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