:notoc: Time Series Made Easy in Python =============================== .. image:: static/darts-logo-light.png :alt: darts :align: center :width: 100% :class: only-light .. image:: static/darts-logo-dark.png :alt: darts :align: center :width: 100% :class: only-dark .. raw:: html

PyPI version Conda Version Supported versions Docker Image Version GitHub Release Date GitHub Workflow Status Downloads Downloads codecov Code style: black Join the chat at https://gitter.im/u8darts/darts

| **Darts** is a Python library for user-friendly **forecasting and anomaly detection** on time series. It contains a variety of models, from classics such as ARIMA to deep neural networks. All models can be used in the same way, using ``fit()`` and ``predict()`` functions, similar to scikit-learn. The library also makes it easy to backtest models, combine the predictions of several models, and take external data into account. Darts supports both **univariate and multivariate** time series and models, and offers extensive support for **probabilistic forecasting**. .. grid:: 1 2 3 3 :gutter: 4 :padding: 2 2 0 0 :class-container: sd-text-center .. grid-item-card:: Quickstart :class-card: intro-card :shadow: md .. image:: static/grid_card_icons/quickstart.png :class: sd-card-img-top only-light :alt: Quickstart .. image:: static/grid_card_icons_dark/quickstart.png :class: sd-card-img-top only-dark :alt: Quickstart Introduction to Darts' main concepts and workflow +++ .. button-ref:: quickstart/00-quickstart :ref-type: doc :click-parent: :color: secondary :expand: To the quickstart guide .. grid-item-card:: Models :class-card: intro-card :shadow: md .. image:: static/grid_card_icons/models.png :class: sd-card-img-top only-light :alt: Models .. image:: static/grid_card_icons_dark/models.png :class: sd-card-img-top only-dark :alt: Models Available models and supported features +++ .. button-ref:: forecasting-models :ref-type: ref :click-parent: :color: secondary :expand: To the models table .. grid-item-card:: API Reference :class-card: intro-card :shadow: md .. image:: static/grid_card_icons/api.png :class: sd-card-img-top only-light :alt: API Reference .. image:: static/grid_card_icons_dark/api.png :class: sd-card-img-top only-dark :alt: API Reference Detailed API documentation with methods and parameters +++ .. button-ref:: generated_api/darts :ref-type: doc :click-parent: :color: secondary :expand: To the API reference .. grid-item-card:: Examples :class-card: intro-card :shadow: md .. image:: static/grid_card_icons/examples.png :class: sd-card-img-top only-light :alt: Examples .. image:: static/grid_card_icons_dark/examples.png :class: sd-card-img-top only-dark :alt: Examples Jupyter notebooks with basic and advanced tutorials +++ .. button-ref:: examples :ref-type: doc :click-parent: :color: secondary :expand: To the examples .. grid-item-card:: User Guide :class-card: intro-card :shadow: md .. image:: static/grid_card_icons/user-guide.png :class: sd-card-img-top only-light :alt: User Guide .. image:: static/grid_card_icons_dark/user-guide.png :class: sd-card-img-top only-dark :alt: User Guide In-depth information on key concepts and features +++ .. button-ref:: userguide :ref-type: doc :click-parent: :color: secondary :expand: To the user guide .. grid-item-card:: How to Contribute :class-card: intro-card :shadow: md .. image:: static/grid_card_icons/contribute.png :class: sd-card-img-top only-light :alt: Contribute .. image:: static/grid_card_icons_dark/contribute.png :class: sd-card-img-top only-dark :alt: Contribute Guidelines for contributing to the Darts library +++ .. button-link:: https://github.com/unit8co/darts/blob/master/CONTRIBUTING.md :click-parent: :color: secondary :expand: To the contributing guide ---- High Level Introductions ------------------------- * `Introductory Blog Post `_ * `Introduction video (25 minutes) `_ Articles on Selected Topics --------------------------- * `Training Models on Multiple Time Series `_ * `Using Past and Future Covariates `_ * `Temporal Convolutional Networks and Forecasting `_ * `Probabilistic Forecasting `_ * `Transfer Learning for Time Series Forecasting `_ * `Hierarchical Forecast Reconciliation `_ Quick Install ------------- We recommend to first setup a clean Python environment for your project with Python 3.10+ using your favorite tool (`conda `_, `venv `_, `virtualenv `_ with or without `virtualenvwrapper `_). Once your environment is set up you can install darts using pip: .. code-block:: bash pip install darts For more details you can refer to our `installation instructions `_. Example Usage ------------- Forecasting ~~~~~~~~~~~ Create a ``TimeSeries`` object from a Pandas DataFrame, and split it in train/validation series: .. code-block:: python import pandas as pd from darts import TimeSeries # Read a pandas DataFrame df = pd.read_csv("AirPassengers.csv", delimiter=",") # Create a TimeSeries, specifying the time and value columns series = TimeSeries.from_dataframe(df, "Month", "#Passengers") # Set aside the last 36 months as a validation series train, val = series[:-36], series[-36:] Fit an exponential smoothing model, and make a (probabilistic) prediction over the validation series' duration: .. code-block:: python from darts.models import ExponentialSmoothing model = ExponentialSmoothing() model.fit(train) prediction = model.predict(len(val), num_samples=1000) Plot the median, 5th and 95th percentiles: .. code-block:: python import matplotlib.pyplot as plt series.plot() prediction.plot(label="forecast", low_quantile=0.05, high_quantile=0.95) plt.legend() .. image:: https://github.com/unit8co/darts/raw/master/static/images/example.png :alt: darts forecast example :align: center Anomaly Detection ~~~~~~~~~~~~~~~~~ Load a multivariate series, trim it, keep 2 components, split train and validation sets: .. code-block:: python from darts.datasets import ETTh2Dataset series = ETTh2Dataset().load()[:10000][["MUFL", "LULL"]] train, val = series.split_before(0.6) Build a k-means anomaly scorer, train it on the train set and use it on the validation set to get anomaly scores: .. code-block:: python from darts.ad import KMeansScorer scorer = KMeansScorer(k=2, window=5) scorer.fit(train) anom_score = scorer.score(val) Build a binary anomaly detector and train it over train scores, then use it over validation scores to get binary anomaly classification: .. code-block:: python from darts.ad import QuantileDetector detector = QuantileDetector(high_quantile=0.99) detector.fit(scorer.score(train)) binary_anom = detector.detect(anom_score) Plot (shifting and scaling some of the series to make everything appear on the same figure): .. code-block:: python import matplotlib.pyplot as plt series.plot() (anom_score / 2. - 100).plot(label="computed anomaly score", c="orangered", lw=3) (binary_anom * 45 - 150).plot(label="detected binary anomaly", lw=4) .. image:: https://github.com/unit8co/darts/raw/master/static/images/example_ad.png :alt: darts anomaly detection example :align: center Features -------- * **Forecasting Models:** A large collection of forecasting models for regression as well as classification tasks; from statistical models (such as ARIMA) to deep learning models (such as N-BEATS). See the forecasting models table below. * **Anomaly Detection:** The ``darts.ad`` module contains a collection of anomaly scorers, detectors and aggregators, which can all be combined to detect anomalies in time series. It is easy to wrap any of Darts forecasting or filtering models to build a fully fledged anomaly detection model that compares predictions with actuals. The ``PyODScorer`` makes it trivial to use PyOD detectors on time series. * **Multivariate Support:** ``TimeSeries`` can be multivariate - i.e., contain multiple time-varying dimensions/columns instead of a single scalar value. Many models can consume and produce multivariate series. * **Multiple Series Training (Global Models):** All machine learning based models (incl. all neural networks) support being trained on multiple (potentially multivariate) series. This can scale to large datasets too. * **Probabilistic Support:** ``TimeSeries`` objects can (optionally) represent stochastic time series; this can for instance be used to get confidence intervals, and many models support different flavours of probabilistic forecasting (such as estimating parametric distributions or quantiles). Some anomaly detection scorers are also able to exploit these predictive distributions. * **Conformal Prediction Support:** Our conformal prediction models allow to generate probabilistic forecasts with calibrated quantile intervals for any pre-trained global forecasting model. * **Past and Future Covariates Support:** Many models in Darts support past-observed and/or future-known covariate (external data) time series as inputs for producing forecasts. * **Static Covariates Support:** In addition to time-dependent data, ``TimeSeries`` can also contain static data for each dimension, which can be exploited by some models. * **Hierarchical Reconciliation:** Darts offers transformers to perform reconciliation. These can make the forecasts add up in a way that respects the underlying hierarchy. * **Regression Models:** It is possible to plug-in any scikit-learn compatible model to obtain forecasts as functions of lagged values of the target series and covariates. * **Training with Sample Weights:** All global models support being trained with sample weights. They can be applied to each observation, forecasted time step and target column. * **Forecast Start Shifting:** All global models support training and prediction on a shifted output window. This is useful for example for Day-Ahead Market forecasts, or when the covariates (or target series) are reported with a delay. * **Explainability:** Darts has the ability to *explain* some forecasting models using Shap values. * **Data Processing:** Tools to easily apply (and revert) common transformations on time series data (scaling, filling missing values, differencing, boxcox, ...) * **Metrics:** A variety of metrics for evaluating time series' goodness of fit; from R2-scores to Mean Absolute Scaled Error. * **Backtesting:** Utilities for simulating historical forecasts, using moving time windows. * **PyTorch Lightning Support:** All deep learning models are implemented using PyTorch Lightning, supporting among other things custom callbacks, GPUs/TPUs training and custom trainers. * **Filtering Models:** Darts offers three filtering models: ``KalmanFilter``, ``GaussianProcessFilter``, and ``MovingAverageFilter``, which allow to filter time series, and in some cases obtain probabilistic inferences of the underlying states/values. * **Datasets:** The ``darts.datasets`` submodule contains some popular time series datasets for rapid and reproducible experimentation. * **Compatibility with Multiple Backends:** ``TimeSeries`` objects can be created from and exported to various backends such as pandas, polars, numpy, pyarrow, xarray, and more, facilitating seamless integration with different data processing libraries. .. _forecasting-models: Forecasting Models ------------------ Here's a breakdown of the forecasting models currently implemented in Darts. Our suite includes both regression and classification models, each tailored for specific forecasting tasks. We are committed to expanding our offerings with new models and features to enhance your forecasting capabilities. Regression Models ~~~~~~~~~~~~~~~~~ Our regression models are designed to predict continuous numerical values, making them ideal for forecasting future trends and patterns in time series data. Utilize these models to gain insights into potential future outcomes based on historical data. .. list-table:: :header-rows: 1 :widths: 30 10 10 10 10 20 * - Model - Target Series Support: Univariate / Multivariate - Covariates Support: Past-observed / Future-known / Static - Probabilistic Forecasting: Sampled / Distribution Parameters - Training & Forecasting on Multiple Series - Sources * - **Baseline Models** (`LocalForecastingModel `_) - - - - - * - `NaiveMean `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - πŸ”΄ - * - `NaiveSeasonal `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - πŸ”΄ - * - `NaiveDrift `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - πŸ”΄ - * - `NaiveMovingAverage `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - πŸ”΄ - * - **Statistical / Classic Models** (`LocalForecastingModel `_) - - - - - * - `ARIMA `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… πŸ”΄ - πŸ”΄ - * - `VARIMA `_ - πŸ”΄ βœ… - πŸ”΄ βœ… πŸ”΄ - βœ… πŸ”΄ - πŸ”΄ - * - `ExponentialSmoothing `_ - βœ… πŸ”΄ - πŸ”΄ πŸ”΄ πŸ”΄ - βœ… πŸ”΄ - πŸ”΄ - * - `Theta `_ and `FourTheta `_ - βœ… πŸ”΄ - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - πŸ”΄ - `Theta paper `_ & `4 Theta source `_ * - `Prophet `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… πŸ”΄ - πŸ”΄ - `Prophet repo `_ * - `FFT `_ (Fast Fourier Transform) - βœ… πŸ”΄ - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - πŸ”΄ - * - `KalmanForecaster `_ using the Kalman filter and N4SID for system identification - βœ… βœ… - πŸ”΄ βœ… πŸ”΄ - βœ… πŸ”΄ - πŸ”΄ - `N4SID paper `_ * - `TBATS `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `TBATS paper `_ * - `Croston `_ method - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - * - `StatsForecastModel `_ wrapper around any `StatsForecast `_ model - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - `AutoARIMA `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - `AutoETS `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - `AutoCES `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - `AutoMFLES `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - `AutoTBATS `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - `AutoTheta `_ - βœ… πŸ”΄ - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - πŸ”΄ - `Nixtla's statsforecast `_ * - **Global Baseline Models** (`GlobalForecastingModel `_) - - - - - * - `GlobalNaiveAggregate `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - βœ… - * - `GlobalNaiveDrift `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - βœ… - * - `GlobalNaiveSeasonal `_ - βœ… βœ… - πŸ”΄ πŸ”΄ πŸ”΄ - πŸ”΄ πŸ”΄ - βœ… - * - **Regression Models** (`GlobalForecastingModel `_) - - - - - * - `SKLearnModel `_: wrapper around any scikit-learn-like regression model - βœ… βœ… - βœ… βœ… βœ… - πŸ”΄ πŸ”΄ - βœ… - * - `LinearRegressionModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `RandomForestModel `_ - βœ… βœ… - βœ… βœ… βœ… - πŸ”΄ πŸ”΄ - βœ… - * - `CatBoostModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `LightGBMModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `XGBModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - **PyTorch (Lightning)-based Models** (`GlobalForecastingModel `_) - - - - - * - `RNNModel `_ (incl. LSTM and GRU); equivalent to DeepAR in its probabilistic version - βœ… βœ… - πŸ”΄ βœ… πŸ”΄ - βœ… βœ… - βœ… - `DeepAR paper `_ * - `BlockRNNModel `_ (incl. LSTM and GRU) - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `NBEATSModel `_ - βœ… βœ… - βœ… πŸ”΄ πŸ”΄ - βœ… βœ… - βœ… - `N-BEATS paper `_ * - `NHiTSModel `_ - βœ… βœ… - βœ… πŸ”΄ πŸ”΄ - βœ… βœ… - βœ… - `N-HiTS paper `_ * - `TCNModel `_ - βœ… βœ… - βœ… πŸ”΄ πŸ”΄ - βœ… βœ… - βœ… - `TCN paper `_, `DeepTCN paper `_, `blog post `_ * - `TransformerModel `_ - βœ… βœ… - βœ… πŸ”΄ πŸ”΄ - βœ… βœ… - βœ… - * - `TFTModel `_ (Temporal Fusion Transformer) - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `TFT paper `_, `PyTorch Forecasting `_ * - `DLinearModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `DLinear paper `_ * - `NLinearModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `NLinear paper `_ * - `TiDEModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `TiDE paper `_ * - `TSMixerModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `TSMixer paper `_, `PyTorch Implementation `_ * - **Foundation Models** (`GlobalForecastingModel `_): No training required - - - - - * - `Chronos2Model `_ - βœ… βœ… - βœ… βœ… πŸ”΄ - βœ… βœ… - βœ… - `Chronos-2 report `_, `Amazon blog post `_ * - **Ensemble Models** (`GlobalForecastingModel `_): Model support is dependent on ensembled forecasting models and the ensemble model itself - - - - - * - `NaiveEnsembleModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `RegressionEnsembleModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - **Conformal Models** (`GlobalForecastingModel `_): Model support is dependent on the forecasting model used - - - - - * - `ConformalNaiveModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `Conformalized Prediction `_ * - `ConformalQRModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - `Conformalized Quantile Regression `_ Classification Models ~~~~~~~~~~~~~~~~~~~~~ Classification models in Darts are designed to predict categorical class labels, enabling effective time series labeling and future class prediction. These models are perfect for scenarios where identifying distinct categories or states over time is crucial. .. list-table:: :header-rows: 1 :widths: 30 10 10 10 10 20 * - Model - Target Series Support: Univariate / Multivariate - Covariates Support: Past-observed / Future-known / Static - Probabilistic Forecasting: Sampled / Distribution Parameters - Training & Forecasting on Multiple Series - Sources * - **Regression Models** (`GlobalForecastingModel `_) - - - - - * - `SKLearnClassifierModel `_: wrapper around any scikit-learn-like classification model - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `CatBoostClassifierModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `LightGBMClassifierModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - * - `XGBClassifierModel `_ - βœ… βœ… - βœ… βœ… βœ… - βœ… βœ… - βœ… - Community & Contact ------------------- Anyone is welcome to join our `Gitter room `_ to ask questions, make proposals, discuss use-cases, and more. If you spot a bug or have suggestions, GitHub issues are also welcome. If what you want to tell us is not suitable for Gitter or Github, feel free to send us an email at darts@unit8.co for darts related matters or info@unit8.co for any other inquiries. Contribute ---------- The development is ongoing, and we welcome suggestions, pull requests and issues on GitHub. All contributors will be acknowledged on the `change log page `_. Before working on a contribution (a new feature or a fix), `check our contribution guidelines `_. Citation -------- If you are using Darts in your scientific work, we would appreciate citations to the following JMLR paper. `Darts: User-Friendly Modern Machine Learning for Time Series `_ Bibtex entry: .. code-block:: bibtex @article{JMLR:v23:21-1177, author = {Julien Herzen and Francesco LΓ€ssig and Samuele Giuliano Piazzetta and Thomas Neuer and LΓ©o Tafti and Guillaume Raille and Tomas Van Pottelbergh and Marek Pasieka and Andrzej Skrodzki and Nicolas Huguenin and Maxime Dumonal and Jan KoΕ›cisz and Dennis Bader and FrΓ©dΓ©rick Gusset and Mounir Benheddi and Camila Williamson and Michal Kosinski and Matej Petrik and GaΓ«l Grosch}, title = {Darts: User-Friendly Modern Machine Learning for Time Series}, journal = {Journal of Machine Learning Research}, year = {2022}, volume = {23}, number = {124}, pages = {1-6}, url = {http://jmlr.org/papers/v23/21-1177.html} } .. toctree:: :hidden: Quickstart .. toctree:: :hidden: User Guide .. toctree:: :hidden: API Reference .. toctree:: :hidden: Examples .. toctree:: :hidden: Release Notes