Log In Sign Up

Darts: User-Friendly Modern Machine Learning for Time Series

by   Julien Herzen, et al.

We present Darts, a Python machine learning library for time series, with a focus on forecasting. Darts offers a variety of models, from classics such as ARIMA to state-of-the-art deep neural networks. The emphasis of the library is on offering modern machine learning functionalities, such as supporting multidimensional series, meta-learning on multiple series, training on large datasets, incorporating external data, ensembling models, and providing a rich support for probabilistic forecasting. At the same time, great care goes into the API design to make it user-friendly and easy to use. For instance, all models can be used using fit()/predict(), similar to scikit-learn.


page 1

page 2

page 3

page 4


sktime: A Unified Interface for Machine Learning with Time Series

We present sktime -- a new scikit-learn compatible Python library with a...

TimeGym: Debugging for Time Series Modeling in Python

We introduce the TimeGym Forecasting Debugging Toolkit, a Python library...

Graph Neural Networks for Model Recommendation using Time Series Data

Time series prediction aims to predict future values to help stakeholder...

Merlion: A Machine Learning Library for Time Series

We introduce Merlion, an open-source machine learning library for time s...

A Survey on Semi-parametric Machine Learning Technique for Time Series Forecasting

Artificial Intelligence (AI) has recently shown its capabilities for alm...

Multivariate Power Series in Maple

We present MultivariatePowerSeries, a Maple library introduced in Maple ...

1 Introduction

Time series forecasting has numerous industrial and scientific applications in logistics, predictive maintenance, energy, manufacturing, agriculture, healthcare, sales, climate science, and many other domains. While classical methods such as ARIMA and Exponential Smoothing often give good results (Hyndman and Athanasopoulos, 2018), machine learning is becoming a more attractive option to improve the models’ representation power and scale to larger datasets and higher dimensionalities. In fact, it has recently been shown that pure ML-based approaches based on generic deep learning architectures can beat classical methods on a variety of tasks (Oreshkin et al., 2019; Flunkert et al., 2017).

Perhaps more important than sheer accuracy, the arrival of modern machine learning opens the opportunity to re-think the forecasting practices and software. For example, classical methods typically require training one model per time series, whereas ML models usually work best when trained on datasets containing large numbers of time series. This and other paradigm changes – such as better support for high-dimensional data, iterative training based on stochastic gradient descent, or the possibility to tailor loss functions for specific needs – require new tools and appropriate APIs. In particular, user-friendly and powerful APIs are important to make ML approaches as easy to use as classical techniques, which is necessary for larger-scale adoption by practitioners.

Several strong time series forecasting toolkits exist; however, they focus on classical methods or do not support deep learning and training models on multiple series (Hyndman and Khandakar, 2008; Jiang et al., 2021; Löning et al., 2019; Hosseini et al., 2021; Bhatnagar et al., 2021), or have lower-level APIs (Alexandrov et al., 2020; Beitner et al., ). Darts proposes a new relatively high-level API unifying classical and ML-based forecasting models.

2 Design Principles and Main Features of Darts

2.1 Time Series Representation

Darts has its own TimeSeries data container type, which represents one time series. TimeSeries are immutable and provide guarantees that the data represents a well-formed time series with correct shape, type, and sorted time index. TimeSeries can be indexed either with Pandas DatetimeIndex or Int64Index (Wes McKinney, 2010). The TimeSeries are wrapping around three-dimensional xarray DataArray (Hoyer and Hamman, 2017). The dimensions are (time, component, sample), where component represents the dimensions of multivariate series and sample represents samples of stochastic time series. The TimeSeries class provides several methods to convert to/from other common types, such as Pandas Dataframes or NumPy arrays (Harris et al., 2020)

. It can also perform convenient operations, such as math operations, indexing, splitting, time-differencing, interpolating, mapping functions, embedding timestamps, plotting, or computing marginal quantiles. For immutability,

TimeSeries carry their own copy of the data and heavily rely on NumPy views for efficiently accessing the data without copying (e.g., when training models).

The main advantage of using a dedicated type offering such guarantees is that all models in Darts can consume and produce TimeSeries, which in turn helps to offer a consistent API. For instance, it is easy to have models consuming the outputs of other models.

2.2 Unified High-Level Forecasting API

All models in Darts support the same basic fit(series: TimeSeries) -> None and predict(n: int) -> TimeSeries interface to be trained on a single series series and forecast n time steps after the end of the series. In addition, most models also provide richer functionalities; for instance the ability to be trained on a Sequence of TimeSeries (using calls like fit([series1, series2, …])). Models can have different internal mechanics (e.g., sequence-to-sequence, fixed lengths, recurrent, auto-regressive), and this unified API makes it possible to seamlessly compare, backtest, and ensemble diverse models without having to know their inner workings.

Some of the models implemented in Darts at the time of writing are: (V)ARIMA, Exponential Smoothing, AutoARIMA (Smith et al., 2017), Theta (Assimakopoulos and Nikolopoulos, 2000), Prophet (Taylor and Letham, 2018), FFT-based forecasting, RNN models similar to DeepAR (Flunkert et al., 2017), N-BEATS (Oreshkin et al., 2019), TCN (Bai et al., 2018) and generic regression models that can wrap around any external tabular regression model (such as scikit-learn models). The list is constantly expanding and we welcome external and reference implementations of new models.

2.3 Meta-Learning

An important part of Darts is the support for meta-learning, or the ability to train one model on a potentially large number of separate time series (Oreshkin et al., 2021). The module contains various implementations of time series datasets

, which specify how to slice series (and potential covariates) into training samples. Darts selects a model-specific default slicing logic, but it can also be user-defined in a custom way if needed. All neural networks are implemented using PyTorch

(Paszke et al., 2019) and support GPU training and inference. It is possible to consume large datasets that do not hold in memory by relying on custom Sequence implementations to load the data in a lazy fashion.

2.4 Support for Past and Future Covariates

Several models support covariate series as a way to specify external data potentially helpful for forecasting the target series. Darts differentiates future covariates, which are known into the future (such as weather forecasts) from past covariates, which are known only into the past. The models accept past_covariates and/or future_covariates arguments, which make it clear whether future values are required at inference time and reduces the risks to make mistakes. Covariate series need not be aligned with the targets, as the alignment is done by the slicing logic based on the respective time axes.

2.5 Probabilistic Forecasting

Some models (and nearly all deep learning models) in Darts support probabilistic forecasting. The joint distributions over components and time are represented by storing Monte Carlo samples in the


objects directly. This representation is very flexible as it does not rely on any parametric form and can capture arbitrary joint distributions. The computational cost of sampling is usually negligible, as samples can be efficiently computed in a vectorized way using batching. Probabilistic deep learning models can fit arbitrary likelihood forms, as long as the negative log-likelihood loss is differentiable. At the time of writing, Darts provides 16 distributions out-of-the-box (both continuous and discrete, univariate and multivariate). Finally, it offers a way to specify time-independent priors on the distributions’ parameters, as a way to specify prior beliefs about the output distributions.

2.6 Other Features

Darts contains many additional features, such as transformers and pipelines for data pre-processing, backtesting (all models offer a backtest() method), grid-search for model selection, extensive metrics, a dynamic time warping module (Berndt and Clifford, 1994), and ensemble models (with the possibility to use a regression model to learn the ensemble itself). Darts also contains filtering

models such as Kalman filters and Gaussian Processes, which offer probabilistic modelling of time series. Finally, the

darts.datasets module contains a variety of publicly available datasets which can be conveniently loaded as TimeSeries.

3 Usage Example

The code below shows how to fit a single TCN model (Bai et al., 2018) with default hyper-parameters on two different (and completely distinct) series, and forecast one of them. The network outputs the parameters of a Laplace distribution. The code contains a complete predictive pipeline, from loading and preprocessing the data, to plotting the forecast with arbitrary quantiles (shown on the right).

from darts.datasets import AirPassengersDataset, MonthlyMilkDataset
from darts.dataprocessing.transformers import Scaler
from darts.models import TCNModel
from darts.utils.likelihood_models import LaplaceLikelihood as LL
air = AirPassengersDataset().load()
milk = MonthlyMilkDataset().load()
scaler_air, scaler_milk = Scaler(), Scaler()
air_s = scaler_air.fit_transform(air)
milk_s = scaler_milk.fit_transform(milk)
model = TCNModel(input_chunk_length=24,
                   likelihood=LL())[air_s, milk_s], epochs=100)
pred = model.predict(n=48, series=air_s,
air_s.plot(label=’original series’)
pred.plot(low_quantile=.1, high_quantile=.9, label=’forecast’)

4 Conclusions

Darts is an attempt at democratizing modern machine learning forecasting approaches, and unify them (along with classical approaches) under a common user-friendly API. The library is still under active development, and some of the future work includes extending the API to include anomaly detection and time series classification models, supporting irregularly spaced data (e.g., point processes), and providing a collection of models pre-trained on large datasets, similar to what exists in the computer vision and NLP domains.