'Extract attributes from the original dataframe used to create a tensorflow dataset
I have the following dataframe df:
sales
2015-10-05 -0.462626
2015-10-06 -0.540147
2015-10-07 -0.450222
2015-10-08 -0.448672
2015-10-09 -0.451773
... ...
2019-10-16 -0.594413
2019-10-17 -0.620770
2019-10-18 -0.586660
2019-10-19 -0.586660
2019-10-20 -0.671934
11340 rows × 1 columns
which I turn into a tf.data.Dataset like so:
data = np.array(df)
ds = tf.keras.utils.timeseries_dataset_from_array(
data=data,
targets=None,
sequence_length=4,
sequence_stride=1,
shuffle=False,
batch_size=1,)
The dataset gives me records looking as such
print(next(iter(ds)))
tf.Tensor(
[[[-0.4626256 ]
[-0.54014736]
[-0.4502221 ]
[-0.44867167]]], shape=(1, 4, 1), dtype=float32)
Which I use for training my ML model, however, I need a way of finding the dates corresponding to the values I fetch from the dataset. Using the example fetch from the dataset above, I want to find the dates corresponding to those consecutive values, which from the dataframe we can see is [2015-10-05, 2015-10-06, 2015-10-07, 2015-10-08]. Ideally, I would like to get other attributes as well if the dataframe has several columns. Is there a way of doing so?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
