Repository: awslabs/gluonts

Issue:
Index of forecast is wrong in multivariate Time Series
## Description
When forecasting multivariate Time Series the index has the length of the target dimension instead of the prediction length

## To Reproduce

```python
import numpy as np

from gluonts.dataset.common import ListDataset
from gluonts.distribution import MultivariateGaussianOutput
from gluonts.model.deepar import DeepAREstimator
from gluonts.trainer import Trainer
from gluonts.evaluation.backtest import make_evaluation_predictions


train_dataset = ListDataset(
    data_iter=[
        {
            "start": "2019-01-01 00:00:00",
            "target": np.ones(shape=(4, 4)),
        },
    ],
    freq="W",
    one_dim_target=False,
)

test_dataset = ListDataset(
    data_iter=[
        {
            "start": "2019-01-01 00:00:00",
            "target": np.ones(shape=(4, 5)),
        },
    ],
    freq="W",
    one_dim_target=False,
)

estimator = DeepAREstimator(
    'W', prediction_length=1, trainer=Trainer(epochs=3, hybridize=False),
    distr_output=MultivariateGaussianOutput(dim=4),
)

predictor = estimator.train(train_dataset)

forecast_it, ts_it = make_evaluation_predictions(dataset=test_dataset, predictor=predictor, num_samples=10)

forecast_list = list(forecast_it)
ts_list = list(ts_it)
```

## Error Message

DatetimeIndex(['2019-02-03', '2019-02-10', '2019-02-17', '2019-02-24'], dtype='datetime64[ns]', freq='W-SUN')

While it should only be ['2019-02-03']

## Environment
- Operating system: Amazon Linux
- Python version: 3.6
- GluonTS version: a96a0cc4 internal




Discussion:
@mbataillou how do you get that output? If I run your code using the master branch, and at the end I execute
```python
print(forecast_list[0].start_date)
print(forecast_list[0].samples.shape)
```

I get

```
2019-02-03 00:00:00
(10, 1, 4)
```

The first seems to be the expected forecast start time, the second is the expected layout of the prediction samples: 10 samples, prediction length 1, dimension of the time series 4.

Hi, I forgot to add it `forecast_list[0].index` is what returns the above.

Resolving patch:
diff --git a/src/gluonts/model/forecast.py b/src/gluonts/model/forecast.py
--- a/src/gluonts/model/forecast.py
+++ b/src/gluonts/model/forecast.py
@@ -373,7 +373,7 @@ def prediction_length(self):
         """
         Time length of the forecast.
         """
-        return self.samples.shape[-1]
+        return self.samples.shape[1]
 
     @property
     def mean(self) -> np.ndarray:


Test patch:
diff --git a/test/model/test_forecast.py b/test/model/test_forecast.py
--- a/test/model/test_forecast.py
+++ b/test/model/test_forecast.py
@@ -94,3 +94,38 @@ def percentile(value):
     assert forecast.prediction_length == pred_length
     assert len(forecast.index) == pred_length
     assert forecast.index[0] == pd.Timestamp(START_DATE)
+
+
+@pytest.mark.parametrize(
+    "forecast, exp_index",
+    [
+        (
+            SampleForecast(
+                samples=np.random.normal(size=(100, 7, 3)),
+                start_date=pd.Timestamp("2020-01-01 00:00:00"),
+                freq="1D",
+            ),
+            pd.date_range(
+                start=pd.Timestamp("2020-01-01 00:00:00"),
+                freq="1D",
+                periods=7,
+            ),
+        ),
+        (
+            DistributionForecast(
+                Uniform(
+                    low=mx.nd.zeros(shape=(5, 2)),
+                    high=mx.nd.ones(shape=(5, 2)),
+                ),
+                start_date=pd.Timestamp("2020-01-01 00:00:00"),
+                freq="W",
+            ),
+            pd.date_range(
+                start=pd.Timestamp("2020-01-01 00:00:00"), freq="W", periods=5,
+            ),
+        ),
+    ],
+)
+def test_forecast_multivariate(forecast, exp_index):
+    assert forecast.prediction_length == len(exp_index)
+    assert np.all(forecast.index == exp_index)