awslabs / gluonts

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

Shape error when using feat_static_cat #871

Closed Christotoooo closed 4 years ago

Christotoooo commented 4 years ago

Hello, thanks for reviewing this:) I am using deepar to forecast sales of multiple products so my input shape might be a little bit different from single time series forecasting. Since I have 1917 time series with 55 categorical features, my input-list shape for "feat_static_cat" is (1917,55). I could not find documentation for multiple ts forecasting of gluonts so that was my best guess based on my experience of using sagemaker. However, that gives me an error:

GluonTSDataError: Array 'feat_static_cat' has bad shape - expected 1 dimensions, got 2.

I am confused about why it is expecting something of dimension 1. Is it because it does not know that I am passing multiple time series?

My model init looks like this:

trainer = Trainer(epochs=100)

estimator = DeepAREstimator(freq="D", prediction_length=28, num_layers = 3,trainer=trainer,use_feat_static_cat=True,cardinality=randomlist)

predictor = estimator.train(training_data=training_data)

Thank you in advance :)

jaheba commented 4 years ago

Hello,

the shape of feat_static_cat should be 55 in this case.

In my view the DeepAR documentation explains how to use it quite well. Note that the field-name is cat instead of feat_static_cat there.

deltawi commented 1 year ago

Hi @Christotoooo I am facing the same issue, I have 12 categorical features but I can't find a way to use them because I get the same error: GluonTSDataError: Array 'feat_static_cat' has bad shape - expected 1 dimensions, got 2 which in my case is normal shape (data_size, n_cat_feature) = (10500, 12).

series = []
for group in sample_df.groupby('ref'):
    id, group_df = group
    series.append({
        FieldName.ITEM_ID: id,
        FieldName.TARGET: group_df[target_col].values,
        FieldName.START: group_df['timestamp'].min(),
        FieldName.FEAT_DYNAMIC_REAL: [group_df[col].values for col in input_cols],
        FieldName.FEAT_STATIC_CAT: [ group_df[col].values for col in static_cat],
    })

from gluonts.dataset.common import ListDataset

# Create GluonTS dataset from list of dictionaries
ds = ListDataset(series, freq='1H')
DushyantSahoo commented 3 months ago

Hi @deltawi Were you able to solve this problem? I am having the same problem, I am not sure how to solve it.

deltawi commented 3 months ago

Hi @deltawi Were you able to solve this problem? I am having the same problem, I am not sure how to solve it.

I switched to Pytorch Forecasting library which implements TFT and is a lot more stable than gluonTS.