Views
No views yet

pip install git+https://github.com/amazon-science/chronos-forecasting.git1import matplotlib.pyplot as plt
2import numpy as np
3import pandas as pd
4import torch
5from chronos import ChronosPipeline
6
7pipeline = ChronosPipeline.from_pretrained(
8 "amazon/chronos-t5-tiny",
9 device_map="cuda",
10 torch_dtype=torch.bfloat16,
11)
12
13df = pd.read_csv("https://raw.githubusercontent.com/AileenNielsen/TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv")
14
15# context must be either a 1D tensor, a list of 1D tensors,
16# or a left-padded 2D tensor with batch as the first dimension
17context = torch.tensor(df["#Passengers"])
18prediction_length = 12
19forecast = pipeline.predict(context, prediction_length) # shape [num_series, num_samples, prediction_length]
20
21# visualize the forecast
22forecast_index = range(len(df), len(df) + prediction_length)
23low, median, high = np.quantile(forecast[0].numpy(), [0.1, 0.5, 0.9], axis=0)
24
25plt.figure(figsize=(8, 4))
26plt.plot(df["#Passengers"], color="royalblue", label="historical data")
27plt.plot(forecast_index, median, color="tomato", label="median forecast")
28plt.fill_between(forecast_index, low, high, color="tomato", alpha=0.3, label="80% prediction interval")
29plt.legend()
30plt.grid()
31plt.show()@article{ansari2024chronos,
title={Chronos: Learning the Language of Time Series},
author={Ansari, Abdul Fatir and Stella, Lorenzo and Turkmen, Caner and Zhang, Xiyuan, and Mercado, Pedro and Shen, Huibin and Shchur, Oleksandr and Rangapuram, Syama Syndar and Pineda Arango, Sebastian and Kapoor, Shubham and Zschiegner, Jasper and Maddix, Danielle C. and Mahoney, Michael W. and Torkkola, Kari and Gordon Wilson, Andrew and Bohlke-Schneider, Michael and Wang, Yuyang},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2024},
url={https://openreview.net/forum?id=gerNCVqqtR}
}