Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example code in timeseries_dataset.py #14

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions tf_keras/utils/timeseries_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,24 @@ def timeseries_dataset_from_array(
timesteps to predict the next timestep, you would use:

```python
input_data = data[:-10]
targets = data[10:]
data = tf.range(15)
sequence_length = 10
input_data = data[:]
targets = data[sequence_length:]
dataset = tf.keras.utils.timeseries_dataset_from_array(
input_data, targets, sequence_length=10)
input_data, targets, sequence_length=sequence_length
)
for batch in dataset:
inputs, targets = batch
assert np.array_equal(inputs[0], data[:10]) # First sequence: steps [0-9]
# First sequence: steps [0-9]
assert np.array_equal(inputs[0], data[:sequence_length])
# Corresponding target: step 10
assert np.array_equal(targets[0], data[10])
assert np.array_equal(targets[0], data[sequence_length])
break
# To view the generated dataset
for batch in dataset.as_numpy_iterator():
input, label = batch
print(f"Input:{input}, target:{label}")
```

Example 3: Temporal regression for many-to-many architectures.
Expand Down
Loading