Hello,
i am trying to understand code logic of function to get windowed dataset. I started to do excercises in colab “C4_W4_Lab_1_LSTM.ipynb” where i found in the code something that i really don’t understand.
see bellow code to get window dataset from colab:
def windowed_dataset(series, window_size, batch_size, shuffle_buffer):
series = tf.expand_dims(series, axis=-1)
ds = tf.data.Dataset.from_tensor_slices(series)
ds = ds.window(window_size + 1, shift=1, drop_remainder=True)
ds = ds.flat_map(lambda w: w.batch(window_size + 1))
ds = ds.shuffle(shuffle_buffer)
ds = ds.map(lambda w: (w[:-1], w[1:]))
return ds.batch(batch_size).prefetch(1)
what i don’t understand, why in a step : ds = ds.map(lambda w: (w[:-1], w[1:])): we are slicing dataset as followed w[:-1], w[1:]), to be more accurate, why we are getting y value (label) as a slice w[1:] , should not be this w[-1:] instead?
when we slice this as w[1:] we are getting labels with the same shape as we have feature values…
lets say we have dataset [1,2,3,4,5,6]
after slicing we get:
feature window [1,2,3,4,5]
label:[2,3,4,5,6]
should not we rather get sliced window and label by w[-1:] as followed?
feature window [1, 2, 3, 4, 5]
label:[6]
In previous weeks of this course, there were used in code logic target labels either w[-1:] or w[-1], therefore i am confused now, since i thought that each label should be just one target value that should be predicted based on respective featured window to that label.