Here is the code that I am trying to run.
Code Snippet:
from gluonts.dataset import common
from gluonts.model import deepstate
import pandas as pd
url = "https://raw.githubusercontent.com/numenta/NAB/master/data/realTweets/Twitter_volume_AMZN.csv"
df = pd.read_csv(url, header=0, index_col=0)
data = common.ListDataset([{"start": df.index[0],
"target": df.value[:"2015-04-05 00:00:00"]}],
freq="5min")
estimator = deepstate.DeepStateEstimator(freq="5min", prediction_length=12)
predictor = estimator.train(training_data=data)
prediction = next(predictor.predict(data))
print(prediction.mean)
prediction.plot(output_file='graph.png')
Error Message:
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/gluonts/core/component.py", line 424, in init_wrapper model = PydanticModel(**{**nmargs, **kwargs})
File "pydantic/main.py", line 246, in pydantic.main.BaseModel.__init__
File "pydantic/main.py", line 665, in pydantic.main.validate_model
pydantic.error_wrappers.ValidationError: 1 validation error
cardinality
field required (type=value_error.missing)
I am not sure why this is happening. Any help would be much appreciated.
I think this is because of #413:
This PR tries to make sure that DeepStateEstimator is not misused :) The assumption is that DeepStateEstimator is usually applied to dataset of multiple time series that have at least one categorical feature (e.g., an id for each time series). This way comparison against classical state space models that fit a separate model to each time series in the dataset makes sense.
@shrey183 By default the DeepState estimator is assumed to be applied to more than one time series and hence requires setting cardinality in order to use at least one static feature. Since in your case you only pass a single time series, static features are not needed so you can explicitly set the flag use_feat_static_cat to False.
Can you retry with this?
estimator = deepstate.DeepStateEstimator(freq="5min", prediction_length=12, use_feat_static_cat=False)
@rshyamsundar I think cardinality is still required, since it does not have an default value:
@shrey183 By default the
DeepStateestimator is assumed to be applied to more than one time series and hence requires settingcardinalityin order to use at least one static feature. Since in your case you only pass a single time series, static features are not needed so you can explicitly set the flaguse_feat_static_cattoFalse.Can you retry with this?
estimator = deepstate.DeepStateEstimator(freq="5min", prediction_length=12, use_feat_static_cat=False)
@rshyamsundar I tried the following:
estimator = deepstate.DeepStateEstimator(freq=data_traffic.metadata.freq, prediction_length=data_traffic.metadata.prediction_length, use_feat_static_cat=False)
but I get the same validation error:
ValidationError: 1 validation error
cardinality
field required (type=value_error.missing)
@shrey183 sorry cardinality is still a non-optional argument. This should work:
estimator = deepstate.DeepStateEstimator(
freq="5min",
prediction_length=12,
use_feat_static_cat=False,
cardinality=[1]
)
Note: Since you are only training on a single time series, you may also want to adjust default epochs and num_batches_per_epoch of the Trainer argument. For DeepState:
num_batches_per_epoch x epochs x batch_size / dataset_size is equal to the number of passes over the dataset (or epochs in the standard deep learning terminology)
@shrey183 sorry
cardinalityis still a non-optional argument. This should work:estimator = deepstate.DeepStateEstimator(freq="5min", prediction_length=12, use_feat_static_cat=False, cardinality=[1])Note: Since you are only training on a single time series, you may also want to adjust default
epochsandnum_batches_per_epochof theTrainerargument. ForDeepState:
num_batches_per_epoch x epochs x batch_size / cardinality is equal to the number of passes over the dataset (or epochs in the standard deep learning terminology)
This works! Thank you very much for your help.
num_batches_per_epoch x epochs x batch_size / cardinality is equal to the number of passes over the dataset (or epochs in the standard deep learning terminology)
Hi, @rshyamsundar, I am puzzled by your above statement. The inclusion of cardinality doesn't make sense to me. Also Cardinality would be a vector in cases with many static categorical features.
Could you please elaborate on this.
Many thanks in advance!
@VasudevTA I believe "cardinality" in that context refers to the "size of the dataset" -- let me fix that comment to avoid further misunderstandings
Thanks @lostella - This clears up the confusion!
Per the equation num_batches_per_epoch x epochs x batch_size / dataset_size = number of passes over the whole data, if the data_size is really large, say 10K and num_batches=32, epochs=10 and num_batches_per_epoch=10, only 3200/10000 series are used. In that case, are these 3200 series chosen at random from the 10K series?
Most helpful comment
@VasudevTA I believe "cardinality" in that context refers to the "size of the dataset" -- let me fix that comment to avoid further misunderstandings