Skip to content

Update README examples #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,12 @@ pip install git+https://github.com/amazon-science/chronos-forecasting.git
> [!TIP]
> The recommended way of using Chronos for production use cases is through [AutoGluon](https://auto.gluon.ai), which features ensembling with other statistical and machine learning models for time series forecasting as well as seamless deployments on AWS with SageMaker 🧠. Check out the AutoGluon Chronos [tutorial](https://auto.gluon.ai/stable/tutorials/timeseries/forecasting-chronos.html).

> [!NOTE]
> We have added 🧪experimental support for [MLX](https://github.com/ml-explore/mlx) inference. If you have an Apple Silicon Mac, check out the [`mlx`](https://github.com/amazon-science/chronos-forecasting/tree/mlx) branch of this repository for instructions on how to install and use the MLX version of Chronos.

### Forecasting

A minimal example showing how to perform forecasting using Chronos models:

```python
# for plotting, run: pip install pandas matplotlib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about pandas requirement?

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pandas as pd # requires: pip install pandas
import torch
from chronos import ChronosPipeline

Expand All @@ -93,19 +87,27 @@ df = pd.read_csv("https://raw.githubusercontent.com/AileenNielsen/TimeSeriesAnal

# context must be either a 1D tensor, a list of 1D tensors,
# or a left-padded 2D tensor with batch as the first dimension
context = torch.tensor(df["#Passengers"])
prediction_length = 12
# forecast shape: [num_series, num_samples, prediction_length]
forecast = pipeline.predict(
context,
prediction_length,
context=torch.tensor(df["#Passengers"]),
prediction_length=12,
num_samples=20,
temperature=1.0,
top_k=50,
top_p=1.0,
) # forecast shape: [num_series, num_samples, prediction_length]
)
```

More options for `pipeline.predict` can be found with:

```python
print(ChronosPipeline.predict.__doc__)
```

We can now visualize the forecast:

```python
import matplotlib.pyplot as plt # requires: pip install matplotlib
import numpy as np

# visualize the forecast
forecast_index = range(len(df), len(df) + prediction_length)
forecast_index = range(len(df), len(df) + 12)
low, median, high = np.quantile(forecast[0].numpy(), [0.1, 0.5, 0.9], axis=0)

plt.figure(figsize=(8, 4))
Expand Down Expand Up @@ -142,7 +144,7 @@ embeddings, tokenizer_state = pipeline.embed(context)

### Pretraining and fine-tuning

Scripts for pretraining and fine-tuning Chronos models can be found in [this folder](./scripts/training).
Scripts for pretraining and fine-tuning Chronos models can be found in [this folder](./scripts/).

## 🔥 Coverage

Expand Down