'Time Series Prediction of DNN model - shape of prediction does not match with trained labels in windowed dataset

Could you please help me understand bellow behavior of DNN model and prediction on time series?

i have windowed dataset in following manner:

1 Window = 12rows, 10 colls (python shape 12,10):

x_train = 8 rows, 10 columns (python shape 8,10) y_target = 4 rows, 1 column (python shape (1,4) e.g. [0.123 0.256 0.256 0.756]) as y_target for training I used 4 consecutive values of one target column that follows previous x_train in window

i trained model, made a prediction by passing data of shape 8x10, my model made prediction that was just single value (not 4 values that i passed as label during training).. i thought when i have 1,4 label e.g. [0.123 0.256 0.256 0.756] the prediction will be as well as 4x1 shape.

training window:

tf.Tensor(
[[ 4.02535169e+00  0.00000000e+00  0.00000000e+00  0.00000000e+00
   1.99800000e+01  0.00000000e+00  0.00000000e+00  0.00000000e+00
   0.00000000e+00]
 [ 4.07753744e+00  0.00000000e+00  0.00000000e+00  0.00000000e+00
   1.99800000e+01  0.00000000e+00  0.00000000e+00  5.22453331e-03
  -2.28790820e-01]
 [ 4.09434456e+00  0.00000000e+00  0.00000000e+00  0.00000000e+00
   2.20000000e+01  0.00000000e+00  0.00000000e+00 -2.50742401e-03
   6.17255190e-01]
 [ 4.15888308e+00 -7.13000000e+02  1.00000000e+00  8.00000000e-01
   2.10000000e+01  0.00000000e+00 -4.00000000e-01 -1.26333612e-02
  -4.63304780e-01]
 [ 4.35670883e+00  0.00000000e+00  0.00000000e+00  0.00000000e+00
   2.10000000e+01  0.00000000e+00 -2.00000000e-01  1.17386605e-02
   3.93091050e-01]
 [ 4.48863637e+00  0.00000000e+00  0.00000000e+00  0.00000000e+00
   1.99800000e+01  0.00000000e+00  0.00000000e+00  6.29587968e-03
  -1.02870242e+00]
 [ 4.59511985e+00  1.16200000e+03  1.00000000e+00 -4.00000000e-01
   1.99800000e+01  3.00000000e+00  0.00000000e+00 -1.55134861e-03
   9.60246950e-01]
 [ 4.65396035e+00  0.00000000e+00  0.00000000e+00  0.00000000e+00
   1.99800000e+01  0.00000000e+00 -1.00000000e-01 -1.00571548e-02
  -2.19919460e-01]], shape=(8, 9), dtype=float64)

tf.Tensor([4.6443909  4.65396035 4.65396035 4.66343909], shape=(4,), dtype=float64)

Could you explain why the model.predict output just single value, even though there were labelled data with shape 4x1 during training?



Solution 1:[1]

In tensorflow, the first dimension of a data tensor (for example x_train, y_target) shoud be the number of samples, because the data is passed to the model as batches. In your case, if you are only using one sample, you need to reshape x:

x_train = tf.reshape(x_train, [1,8,10])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pierrotb1