awslabs / gluonts

Probabilistic time series modeling in Python
https://ts.gluon.ai
Apache License 2.0
4.63k stars 755 forks source link

The simple example runs to completion, but does not output a plot #3040

Closed sunnyccshine closed 1 year ago

sunnyccshine commented 1 year ago

Description

I ran the simple example from GitHub and it didn't output graphical results, is this normal?

To Reproduce

import pandas as pd
import matplotlib.pyplot as plt

from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from gluonts.torch.model.deepar import DeepAREstimator

# Load data from a CSV file into a PandasDataset
df = pd.read_csv(
    "./AirPassengers.csv",
    index_col=0,
    parse_dates=True,
)
dataset = PandasDataset(df, target="#Passengers")

# Split the data for training and testing
training_data, test_gen = split(dataset, offset=-36)
test_data = test_gen.generate_instances(prediction_length=12, windows=3)

# Train the model and make predictions
model = DeepAREstimator(
    prediction_length=12, freq="M", trainer_kwargs={"max_epochs": 5}
).train(training_data)

forecasts = list(model.predict(test_data.input))

# Plot predictions
plt.plot(df["1954":], color="black")
for forecast in forecasts:
    forecast.plot()
plt.legend(["True values"], loc="upper left", fontsize="xx-large")

Error message or code output

No errors are reported, but the run completes without outputting the plot, it seems that the following code has lost their purpose

# Plot predictions
plt.plot(df["1954":], color="black")
for forecast in forecasts.
    forecast.plot()
plt.legend(["True values"], loc="upper left", fontsize="xx-large")

This is what are shown in the terminal

D:\anaconda\envs\GluonTS\python.exe D:\pythonProject\ForecastPassenger.py 
GPU available: False, used: False
TPU available: False, using: 0 TPU cores
IPU available: False, using: 0 IPUs
HPU available: False, using: 0 HPUs
D:\anaconda\envs\GluonTS\lib\site-packages\pytorch_lightning\trainer\connectors\logger_connector\logger_connector.py:67: UserWarning: Starting from v1.9.0, `tensorboardX` has been removed as a dependency of the `pytorch_lightning` package, due to potential conflicts with other packages in the ML ecosystem. For this reason, `logger=True` will use `CSVLogger` as the default logger, unless the `tensorboard` or `tensorboardX` packages are found. Please `pip install lightning[extra]` or one of them to enable TensorBoard support by default
  warning_cache.warn(
D:\anaconda\envs\GluonTS\lib\site-packages\pytorch_lightning\trainer\configuration_validator.py:70: PossibleUserWarning: You defined a `validation_step` but have no `val_dataloader`. Skipping val loop.
  rank_zero_warn(

  | Name  | Type        | Params | In sizes | Out sizes   
----------------------------------------------------------------
0 | model | DeepARModel | 23.3 K | ?        | [1, 100, 12]
----------------------------------------------------------------
23.3 K    Trainable params
0         Non-trainable params
23.3 K    Total params
0.093     Total estimated model params size (MB)
Epoch 0: : 50it [00:05,  9.23it/s, v_num=7, train_loss=5.860]Epoch 0, global step 50: 'train_loss' reached 5.85503 (best 5.85503), saving model to 'D:\\pythonProject\\lightning_logs\\version_7\\checkpoints\\epoch=0-step=50.ckpt' as top 1
Epoch 1: : 50it [00:04, 10.66it/s, v_num=7, train_loss=4.780]Epoch 1, global step 100: 'train_loss' reached 4.78271 (best 4.78271), saving model to 'D:\\pythonProject\\lightning_logs\\version_7\\checkpoints\\epoch=1-step=100.ckpt' as top 1
Epoch 2: : 50it [00:04, 10.94it/s, v_num=7, train_loss=4.570]Epoch 2, global step 150: 'train_loss' reached 4.57120 (best 4.57120), saving model to 'D:\\pythonProject\\lightning_logs\\version_7\\checkpoints\\epoch=2-step=150.ckpt' as top 1
Epoch 3: : 50it [00:04, 11.07it/s, v_num=7, train_loss=4.360]Epoch 3, global step 200: 'train_loss' reached 4.35962 (best 4.35962), saving model to 'D:\\pythonProject\\lightning_logs\\version_7\\checkpoints\\epoch=3-step=200.ckpt' as top 1
Epoch 4: : 50it [00:05,  9.95it/s, v_num=7, train_loss=4.290]Epoch 4, global step 250: 'train_loss' reached 4.28682 (best 4.28682), saving model to 'D:\\pythonProject\\lightning_logs\\version_7\\checkpoints\\epoch=4-step=250.ckpt' as top 1
`Trainer.fit` stopped: `max_epochs=5` reached.
Epoch 4: : 50it [00:05,  9.89it/s, v_num=7, train_loss=4.290]

Process finished with exit code 0

Environment

lostella commented 1 year ago

plt.show()