Functime Transforms Time Series Data for Precise Forecasting
In today's data-driven landscape, businesses across industries face the critical challenge of accurately forecasting time series data. From predicting sales trends to estimating resource needs, the ability to forecast with precision can give organizations a significant competitive advantage. While traditional statistical methods have long been used for time series analysis, recent advancements in machine learning have opened new possibilities for more accurate and efficient forecasting.
Functime is a cutting-edge Python library developed to address these challenges, combining powerful time series processing with sophisticated forecasting models. Built on top of Polars for high-performance data manipulation, Functime offers a comprehensive suite of tools for time series analysis, including advanced feature extraction, automated model selection, and probabilistic forecasting methods. By providing both intuitive high-level APIs and low-level optimization for parallel processing, the library enables data scientists and engineers to build robust forecasting systems that can handle large-scale time series data.
This technical overview will explore the key components of Functime, from its underlying architecture to its advanced functionality for time series analysis. We'll examine how the library enables efficient data processing and modeling through its integration with Polars, as well as its capabilities for automated feature engineering and model selection. Additionally, we'll demonstrate how Functime's sophisticated forecasting tools can be applied to real-world time series data, enabling data-driven decision-making across various industries.
functime can be installed using pip with several optional packages for advanced forecasting techniques.
To install functime via pip, use the following command:
pip install functime
The package can be extended with several optional components:
ann: Enables forecasting with approximate nearest neighbors using lancedb
cat: Provides catboost forecasting through the catboost library
xgb: Supports xgboost forecasting through the xgboost library
lgb: Offers lightgbm forecasting, requiring compilation with cmake and libomp
llm: Incorporates LLM-powered forecast analysis using OpenAI tokenizers and models
plot: Includes plotting functionality with plotly and Material for MkDocs
The library uses Polars for efficient data processing and supports multiple forecasting models including LightGBM, XGBoost, and CatBoost. The company's solutions operate globally across collections of time series, with each time series operation implemented in Polars for multi-threaded parallelism.
Forecasters automatically select optimal lags via cross-validation within specified ranges, with hyperparameter tuning handled by FLAML's CFO algorithm. Supported forecasters include LightGBM, XGBoost, and CatBoost models, featuring backtesting functionality with expanding_window_split and sliding_window_split strategies. The system supports both expanding and sliding window configurations, delivering high performance even when distributed computing is not required.
For probabilistic forecasting, the library employs quantile regression using LightGBM, XGBoost, and CatBoost models, implementing conformal prediction intervals through EnbPI methodology. Probabilistic interval forecasts are generated using the conformalize function for batch prediction intervals, providing interval estimates at specified percentiles while maintaining efficiency through lazy query execution.
The library supports forecasting at various frequencies, including monthly (1mo), daily (1d), and others. All operations utilize polars.DataFrame or polars.LazyFrame inputs, returning LazyFrames that only execute when the collect() method is called. This design enables efficient optimization of operations on the input data structure, combining lazy evaluation with parallel processing capabilities.
Functime's tools support both deterministic and probabilistic forecasting, delivering real business impact in time series analysis while maintaining computational efficiency. The library has won competitions and demonstrates successful application in diverse forecasting scenarios, including those requiring sophisticated feature engineering and automated model tuning.
Functime provides over 100 time-series feature extractors, with approximately 85% of implementations optimized as lazy queries that work on both polars.Series and polars.Expr. All features are registered under a custom ts Polars namespace, enabling efficient lazy query execution.
The library supports univariate feature extraction as well as feature extraction across multiple time-series via group_by operations. Rolling window extraction capabilities allow for dynamic window sizes across grouped time-series, providing flexibility in feature engineering. The system demonstrates significant performance improvements over existing solutions like tsfresh, delivering up to 200x speed-ups for individual forecasts and over 200x speed-ups for group-by operations.
Supported feature extractors include binned_entropy, lempel_ziv_complexity, and longest_streak_above_mean, among others. These extractors are designed to work seamlessly with Polars' lazy query system, combining query optimization with parallel processing capabilities. The feature extraction process operates directly on polars.DataFrame or polars.LazyFrame inputs, returning LazyFrames that only execute when the collect() method is called. This design enables efficient optimization of operations on the input data structure while maintaining lazy evaluation and parallel processing advantages.
Functime's forecasting strategies include both local and global approaches, with automated lag selection and hyperparameter tuning capabilities. The library supports multiple forecasting models, including LightGBM, XGBoost, and CatBoost, which are selected through cross-validation within specified lag ranges.
The company's forecasters automatically choose optimal lags via cross-validation between minimum and maximum lag values, with hyperparameters tuned using FLAML's CFO algorithm. Supported forecasting strategies include recursive, direct, and ensemble approaches, with backtesting functionality provided through expanding_window_split and sliding_window_split methods.
For probabilistic forecasting, the library implements quantile regression using LightGBM, XGBoost, and CatBoost models, generating prediction intervals with the EnbPI methodology. This approach provides interval estimates at specified percentiles while maintaining efficiency through lazy query execution.
Time-series preprocessing in Functime operates entirely within Polars' lazy query framework, returning LazyFrames that only execute during the collect() method call. This structure enables efficient optimization of preprocessing operations on input data structures while maintaining lazy evaluation and parallel processing advantages.
The library supports several fundamental transformations for preparing time-series data. These include differencing (both regular and seasonal), detrending using linear and mean methods, and the Box-Cox transform for optimizing power-law relationships. Each preprocessing step returns a new LazyFrame, and the original dataset can be restored using the invert() method if needed.
For cases requiring invertible transformations, Functime provides several options:
First-order differencing: This basic transformation is readily invertible using the backward fill strategy.
Seasonal differencing: Allows for flexible lag adjustment with a specified seasonal period, also invertible.
Linear detrending: Removes the linear trend component from each time series, maintaining reversibility.
Mean detrending: Subtracts the mean value for each series, preserving the original data structure through inverse operations.
Non-invertible but powerful preprocessing tools are also available, including:
Local scaling: Standardizes each time series by mean subtraction and standard deviation division.
Rolling statistics: Computes various rolling aggregations (mean, min, max, std) across series, though this operation removes interpretability by altering data values irreversibly.
The company's preprocessing capabilities integrate seamlessly with their forecasting workflows, supporting complex operations through their pipeline capabilities. Features like target and feature transformation enable controlled application of multiple preprocessing steps (up to 100+ transformations) directly within their forecasting framework, facilitating sophisticated feature engineering while maintaining computational efficiency.