unit8co/darts
A python library for user-friendly forecasting and anomaly detection on time series.
Darts – Time‑Series Forecasting & Anomaly Detection in Python
What it is – Darts is an open‑source Python library that makes it easy to work with time‑series data. It provides a unified, scikit‑learn‑style API (fit, predict) for a wide range of models, from classic statistical approaches (ARIMA, Exponential Smoothing) to modern deep‑learning architectures (N‑BEATS, TCN, Transformer‑based models). It also bundles tools for anomaly detection, back‑testing, probabilistic forecasting, and data preprocessing.
Why it matters – Time‑series analysis is a core problem in many industries (finance, energy, retail, IoT). Darts removes the friction of switching between different model families and data formats, letting you prototype, compare, and deploy models quickly, while still supporting advanced features like multi‑series training, covariates, hierarchical reconciliation, and conformal prediction.
Quick start (from the README)
import pandas as pd
from darts import TimeSeries
from darts.models import ExponentialSmoothing
# Load a CSV into a pandas DataFrame
df = pd.read_csv("AirPassengers.csv")
# Convert to a Darts TimeSeries (specify time and value columns)
series = TimeSeries.from_dataframe(df, "Month", "#Passengers")
# Train/validation split
train, val = series[:-36], series[-36:]
# Fit a simple exponential‑smoothing model
model = ExponentialSmoothing()
model.fit(train)
# Probabilistic forecast for the validation horizon (1000 samples)
forecast = model.predict(len(val), num_samples=1000)
# Plot the result
import matplotlib.pyplot as plt
series.plot()
forecast.plot(label="forecast", low_quantile=0.05, high_quantile=0.95)
plt.legend()
plt.show()
Core features (as listed in the README)
| Category | Highlights |
|---|---|
| Forecasting models | Classical (ARIMA, VARIMA, Exponential Smoothing), baseline (Naïve, Moving‑Average), deep learning (N‑BEATS, TCN, Transformer, RNNs) |
| Multivariate support | TimeSeries can hold multiple columns; many models accept multivariate inputs |
| Global‑model training | Neural‑network models can be trained on dozens or thousands of series simultaneously |
| Probabilistic output | Sample‑based forecasts or parametric distributions; useful for confidence intervals |
| Covariates | Past‑observed, future‑known, and static external data can be fed to models |
| Anomaly detection | darts.ad module wraps PyOD scorers, K‑means, quantile detectors, and any forecasting model to produce anomaly scores |
| Back‑testing & evaluation | Utilities for rolling‑window forecasts, a suite of metrics (R², MASE, etc.) |
| Explainability | SHAP‑based explanations for compatible models |
| Hierarchical reconciliation | Transformers to enforce hierarchical consistency in forecasts |
| Integration | PyTorch Lightning back‑end, optional MLflow tracking, Docker image, Conda package, and compatibility with pandas, polars, numpy, pyarrow, xarray |
| Data utilities | Built‑in datasets, scaling, missing‑value handling, differencing, Box‑Cox, etc. |
Typical use cases
- Business demand forecasting – train a global model on many product‑level series, incorporate price or promotion covariates, obtain probabilistic demand intervals.
- Energy load / price prediction – use past weather data (past covariates) and known calendar effects (future covariates) to forecast electricity consumption.
- Anomaly detection in sensor streams – wrap a forecasting model or a PyOD detector with
darts.adto flag out‑of‑distribution behavior. - Hierarchical planning – forecast at SKU level, then reconcile to category or total‑sales level.
- Research & education – quick prototyping of new time‑series architectures thanks to the unified API.
Installation
# Recommended: fresh Python 3.11+ environment (conda/venv/virtualenv)
pip install darts # pulls all core dependencies
For GPU/TPU support or a slimmer install, see the full INSTALL.md in the repo.
Where to learn more
- Quick‑start guide – https://unit8co.github.io/darts/quickstart/00-quickstart.html
- User guide & API reference – https://unit8co.github.io/darts/userguide.html and https://unit8co.github.io/darts/generated_api/darts.html
- Example notebooks – https://unit8co.github.io/darts/examples.html (includes an MLflow demo)
- Blog & video introductions – Medium posts and a 25‑minute YouTube overview linked in the README.
TL;DR
Darts is a production‑ready, Pythonic toolbox for time‑series forecasting and anomaly detection. It unifies classic statistical methods and modern deep‑learning models under a single, scikit‑learn‑like interface, supports multivariate and multi‑series training, offers probabilistic outputs, and integrates with popular ML tooling (PyTorch Lightning, MLflow). Ideal for anyone needing to turn temporal data into reliable predictions without juggling multiple libraries.
Related
- Project
- Project
- Project
- Project
- Project