Skip to main content

Time-series machine learning at scale.

Project description

Time-series machine learning at scale


functime Python PyPi Code style: black GitHub Publish to PyPI GitHub Run Quickstart Discord


functime is a powerful Python library for production-ready global forecasting and time-series feature engineering.

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 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
  • Censored forecaster: for zero-inflated and thresholding forecasts

Additional Highlights

functime comes with a specialized LLM agent to analyze, describe, and compare your forecasts! Check out the walkthrough here. Currently supports OpenAI's GPT-3.5 and GPT-4 as the underyling engine.

Getting Started

Install functime via the pip package manager.

pip install functime

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

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.feature_extraction 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/descendant-ai/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.

LLM Copilot

Requires an OpenAI API key set as an environment variable OPENAI_API_KEY.

import polars as pl
import functime.llm

y = pl.read_parquet("../../data/commodities.parquet")
context = "This dataset comprises of historical commodity prices between 1980 to 2022."

# Analyze trend and seasonality for two commodities
analysis = y_pred.llm.analyze(
    context=dataset_context,
    basket=["Aluminum", "Banana, Europe"]
)
print("📊 Analysis:\n", analysis)

# Compare two baskets of commodities!
basket_a = ["Aluminum", "Banana, Europe"]
basket_b = ["Chicken", "Cocoa"]
comparison = y_pred.llm.compare(
    basket=basket_a,
    other_basket=basket_b
)
print("📊 Comparison:\n", comparison)

View the full walkthrough on the LLM copilot here.

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-0.8.1.tar.gz (76.3 kB view details)

Uploaded Source

Built Distribution

functime-0.8.1-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

Details for the file functime-0.8.1.tar.gz.

File metadata

  • Download URL: functime-0.8.1.tar.gz
  • Upload date:
  • Size: 76.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.5

File hashes

Hashes for functime-0.8.1.tar.gz
Algorithm Hash digest
SHA256 177339f5adcd59ce973b0523369d87ba10764d582c69da394a08667545036a41
MD5 654cb10438c3967a8b1aa143125b91b1
BLAKE2b-256 5f113b02dbcb2779839804b8036154ce8e1764728faf106c4c5bb9dec1d508c1

See more details on using hashes here.

File details

Details for the file functime-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: functime-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 78.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.5

File hashes

Hashes for functime-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a05805a0fb9496150f7f46cbdb879c96c071258dbd838cc947074afbb4fc8e3
MD5 f6d9f05308fd360576c556fb49528679
BLAKE2b-256 b4c407a2bcb3f12623d674aab7c433ba8cf9c1b4bc4f48b481723ccbe261191d

See more details on using hashes here.

Supported by

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