Reputation: 31
I'm using TensorFlow 2.3.1, and the following code is not shuffling the data.
I have time series data that I want to build features and target for prediction.
Code:
data_len = len(calls['Calls'])
# Load data as TensorFlow dataset
dataset = tf.data.Dataset.from_tensor_slices(calls['Calls'])
# Create data windows and shifting values. Drop incomplete arrays
dataset = dataset.window(5, shift=1, drop_remainder=True)
# Convert into tensors for each window
dataset = dataset.flat_map(lambda window: window.batch(5))
# Split into features and target
dataset = dataset.map(lambda window: (window[:-1], window[-1:]))
# Shuffle data
dataset.shuffle(buffer_size=data_len)
dataset.batch(2).prefetch(1)
# Print output
for x, y in dataset:
print('x = {}'.format(x.numpy()))
print('y = {}'.format(y.numpy()))
Result:
x = [1659 4928 3961 3663]
y = [2452]
x = [4928 3961 3663 2452]
y = [2195]
x = [3961 3663 2452 2195]
y = [3796]
x = [3663 2452 2195 3796]
y = [2997]
x = [2452 2195 3796 2997]
y = [2598]
x = [2195 3796 2997 2598]
y = [2605]
x = [3796 2997 2598 2605]
y = [2603]
x = [2997 2598 2605 2603]
y = [2332]
x = [2598 2605 2603 2332]
y = [2025]
x = [2605 2603 2332 2025]
Upvotes: 0
Views: 694
Reputation: 31
Found out the issue.
I wasn't assigning the batching and shuffling back to the dataset.
Thanks anyway.
Upvotes: 3