awslabs / gluonts

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

deepstate asks for cardinality while use_feat_static_cat is set to False #794

Closed stellaywu closed 4 years ago

stellaywu commented 4 years ago

Using gluonts 0.4.2 got error message when trying estimator = DeepStateEstimator( freq='D', prediction_length=prediction_length, past_length=context_length, use_feat_static_cat=False, use_feat_dynamic_real=True, trainer=Trainer(ctx="cpu", epochs=50, learning_rate=1e-3, num_batches_per_epoch=100 ) ) error message as follows. What makes sense to put for cardinality when use_feat_static_cat is set to False? Thank you!

--------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
<ipython-input-454-045457f005f5> in <module>
      9                     epochs=50,
     10                     learning_rate=1e-3,
---> 11                     num_batches_per_epoch=100
     12                    )
     13 )

/anaconda3/lib/python3.7/site-packages/gluonts/core/component.py in init_wrapper(*args, **kwargs)
    422                 if name != "self"
    423             }
--> 424             model = PydanticModel(**{**nmargs, **kwargs})
    425 
    426             # merge nmargs, kwargs, and the model fields into a single dict

/anaconda3/lib/python3.7/site-packages/pydantic/main.py in __init__(__pydantic_self__, **data)
    281         values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
    282         if validation_error:
--> 283             raise validation_error
    284         object.__setattr__(__pydantic_self__, '__dict__', values)
    285         object.__setattr__(__pydantic_self__, '__fields_set__', fields_set)

ValidationError: 1 validation error for DeepStateEstimatorModel
cardinality
  field required (type=value_error.missing)
lostella commented 4 years ago

This may be a bug: I think the intended behavior is that if you disable categorical features then the cardinality is automatically set (to 1). Will get back to you about this, thanks for reporting it!

lostella commented 4 years ago

@stellaywu for the moment, you can just set cardinality=[1] together with use_feat_static_cat=False

stellaywu commented 4 years ago

thanks for the quick fix! @lostella Does cardinality= [1] do anything? the results looks different with different cardinality value. Another somewhat related question - If I want to predict multiple time series at the same time, is it correct to just feed them all at once in one model?

lostella commented 4 years ago

thanks for the quick fix! @lostella

You're welcome, but no fix was involved :-) this is just the way to make it work when you set feat_static_cat=False, currently. We should either improve the documentation there, or improve the API of this estimator in some way (see #799 for related discussion)

Does cardinality= [1] do anything? the results looks different with different cardinality value.

When you set feat_static_cat=False, the model injects fake categorical features in the data, all equal to zero. So there is one categorical feature with cardinality 1, so you should set it to [1]. Other settings may also work (in the sense that the model runs) but I'm not sure how that will affect the quality of the model.

Another somewhat related question - If I want to predict multiple time series at the same time, is it correct to just feed them all at once in one model?

That's correct, once you've trained a predictor, you can use it to predict a whole dataset of time series at once, and it will return to you an iterator over the forecast objects, one for each element in the input dataset.