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

Uploaded Source

Built Distribution

functime-0.8.0-py3-none-any.whl (78.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: functime-0.8.0.tar.gz
  • Upload date:
  • Size: 76.8 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.0.tar.gz
Algorithm Hash digest
SHA256 e2fe638aab99150e452bfe015ae05f1fd8970e2c5991c7c311eb9f0c92dae4f7
MD5 276e1f0eeb3464e630c052f12ebdcf61
BLAKE2b-256 a2ecb84b499b739fd6e3db056944c9b451ce367e1305d6c0ac5d4bcc9a320b75

See more details on using hashes here.

File details

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

File metadata

  • Download URL: functime-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 78.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64c72aa73311561ede51f20b95fc64bae769d820ebe6bf6fdfbe594e10d617c6
MD5 160947542670ae8e71abe8293eb49dbd
BLAKE2b-256 018e153fe8ca0bcb86aafe0a5b553e690ccaa7e9513d9cd677c734d700d021c0

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