gluonts icon indicating copy to clipboard operation
gluonts copied to clipboard

fix bug local variable 'lv' referenced before assignment

Open binhmuc opened this issue 4 years ago • 2 comments

Issue #, if available: When i train with validate data like this: predictor = estimator.train(training_data = train, validation_data =valid) I got problem:

UnboundLocalError: local variable 'lv' referenced before assignment

Description of changes:

I make lv is global variable.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

binhmuc avatar May 04 '20 07:05 binhmuc

Hello @binhmuc, thanks for opening the PR!

I think just declaring lv as global is not going to fix the issue. This seems to happen when the input-data to train is empty.

jaheba avatar May 04 '20 10:05 jaheba

My impression is, that the error occurs if one supplies a validation set to the train method of a multivariate model, f.e. GPVAR. Running the code below produces the error, while running the code without a validaten set works fine.

from gluonts.dataset.common import TrainDatasets
from gluonts.dataset.multivariate_grouper import MultivariateGrouper
from gluonts.dataset.repository.datasets import get_dataset
from gluonts.model.gpvar import GPVAREstimator
from gluonts.trainer import Trainer

NUM_OF_SERIES = 8


def load_multivariate_dataset(dataset_name: str):
    ds = get_dataset(dataset_name)
    grouper_train = MultivariateGrouper(max_target_dim=NUM_OF_SERIES)
    grouper_test = MultivariateGrouper(max_target_dim=NUM_OF_SERIES)
    return TrainDatasets(
        metadata=ds.metadata,
        train=grouper_train(ds.train),
        test=grouper_test(ds.test),
    )


dataset = load_multivariate_dataset(
    dataset_name="exchange_rate"
)
metadata = dataset.metadata

estimator = GPVAREstimator(
    prediction_length=metadata.prediction_length,
    target_dim=NUM_OF_SERIES,
    freq=metadata.freq,
    trainer=Trainer(
        epochs=50,
        batch_size=4,
        num_batches_per_epoch=10,
        patience=5,
    )
)

predictor = estimator.train(
    training_data=dataset.train, validation_data=dataset.test)

kaijennissen avatar Aug 11 '20 18:08 kaijennissen