Introduction to GluonTS
GluonTS is a powerful Python package designed for probabilistic time series modeling, with a special focus on models that utilize deep learning techniques. The package builds on the foundational strengths of PyTorch and MXNet, providing a robust environment for developing sophisticated statistical models that can predict future values based on historical data.
Key Features
Deep Learning Models
GluonTS leverages the latest advancements in deep learning to offer a suite of models tailored for time series forecasting. These models are capable of capturing complex patterns within the data, which traditional methods might overlook.
Probabilistic Forecasting
One of the standout capabilities of GluonTS is its emphasis on probabilistic forecasting. Instead of merely predicting a single future outcome, GluonTS provides a range of possible future outcomes along with their probabilities. This is immensely valuable in real-world applications where understanding the uncertainty is as crucial as the most likely forecast.
Pretrained Models with Chronos
A recent addition to the GluonTS ecosystem is Chronos, a suite of pretrained models designed for zero-shot time series forecasting. Zero-shot forecasting means the ability to make accurate predictions on new time series data that the model has not encountered during its training. This feature dramatically reduces the preparation time required for using predictive models on new datasets.
Installation
Installing GluonTS is straightforward and can be done via Python's package manager, pip. It requires Python version 3.7 or newer. Depending on the models you intend to use, you can install it with support for either PyTorch or MXNet:
# Install with PyTorch support
pip install "gluonts[torch]"
# Install with MXNet support
pip install "gluonts[mxnet]"
Additional guidance and detailed installation instructions can be found in the GluonTS documentation.
Quick Start Example
To get a better sense of what GluonTS can do, consider an example where a DeepAR model is trained using the airpassengers dataset. This dataset contains monthly passenger numbers from 1949 to 1960. The model is trained on the first nine years of data, then tasked with predicting the next three years:
import pandas as pd
import matplotlib.pyplot as plt
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from gluonts.torch import DeepAREstimator
# Load and prepare the dataset
df = pd.read_csv("https://raw.githubusercontent.com/AileenNielsen/"
"TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv",
index_col=0, parse_dates=True)
dataset = PandasDataset(df, target="#Passengers")
# Split data into training and testing sets
training_data, test_gen = split(dataset, offset=-36)
test_data = test_gen.generate_instances(prediction_length=12, windows=3)
# Train the model and create forecasts
model = DeepAREstimator(prediction_length=12, freq="M", trainer_kwargs={"max_epochs": 5})
model.train(training_data)
forecasts = list(model.predict(test_data.input))
# Plot the results
plt.plot(df["1954":], color="black")
for forecast in forecasts:
forecast.plot()
plt.legend(["True values"], loc="upper left", fontsize="xx-large")
plt.show()
In the plot, the forecasts are represented as probability distributions, with shaded areas indicating the 50% and 90% prediction intervals.
Contributing to GluonTS
The GluonTS community welcomes contributions from developers and researchers. Those interested in contributing should consult the contribution guidelines provided by the project.
Academic Citations
For those using GluonTS in academic work, it is recommended to cite the relevant publications associated with the package to acknowledge the authors' contributions.
Additional Resources
GluonTS offers extensive documentation for stable and development versions. Furthermore, there are a number of tutorials and workshops available, such as presentations from IJCAI 2021, WWW 2020, and others. These resources provide valuable insights and hands-on learning for anyone looking to harness the full potential of GluonTS in their projects.