Darts

0.43.0 · active · verified Thu Apr 16

Darts is a Python library for user-friendly forecasting and anomaly detection on time series. It offers a unified API for a wide range of models, from classical statistical methods like ARIMA to advanced deep learning architectures such as LSTM and Transformers. The library also includes tools for model evaluation, backtesting, handling multiple time series, and incorporating external covariates. It is actively maintained with frequent minor releases, typically on a monthly basis. [1, 2, 4, 9, 11, 13, 16, 22]

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a `TimeSeries` object from a Pandas DataFrame, split it into training and validation sets, fit an `ExponentialSmoothing` model, and generate a forecast. The example then plots the actual series against the predicted values. [4, 8, 11, 12, 13]

import pandas as pd
from darts import TimeSeries
from darts.models import ExponentialSmoothing
import matplotlib.pyplot as plt

# Create a sample DataFrame (replace with your data)
df = pd.DataFrame({
    'Month': pd.to_datetime(pd.date_range(start='2000-01-01', periods=120, freq='MS')),
    '#Passengers': [100 + i + (i**1.2) * 0.5 for i in range(120)] # Example data
})

# Create a TimeSeries object
series = TimeSeries.from_dataframe(df, 'Month', '#Passengers')

# Split data into training and validation sets
train, val = series[:-12], series[-12:]

# Initialize and fit a model
model = ExponentialSmoothing()
model.fit(train)

# Make a prediction
prediction = model.predict(len(val))

# Plot the results
series.plot(label='actual')
prediction.plot(label='forecast')
plt.title('Darts Quickstart Forecast')
plt.show()

view raw JSON →