handson-ml3 icon indicating copy to clipboard operation
handson-ml3 copied to clipboard

`target_col` not used in `to_seq2seq_dataset` in Chapter 15.

Open slievens opened this issue 1 year ago • 1 comments

The code for to_seq2seq_dataset is this

def to_seq2seq_dataset(series, seq_length=56, ahead=14, target_col=1,
                       batch_size=32, shuffle=False, seed=None):
    ds = to_windows(tf.data.Dataset.from_tensor_slices(series), ahead + 1)
    ds = to_windows(ds, seq_length).map(lambda S: (S[:, 0], S[:, 1:, 1]))
    if shuffle:
        ds = ds.shuffle(8 * batch_size, seed=seed)
    return ds.batch(batch_size)

but this doesn't seem to use the value of target_col. Should it not be

ds = to_windows(ds, seq_length).map(lambda S: (S[:, 0], S[:, 1:, target_col]))

on the second line?

slievens avatar Jun 24 '23 10:06 slievens

Yes, you are correct. In the provided code, it seems that the value of target_col is not being used correctly. The line should be modified to ds = to_windows(ds, seq_length).map(lambda S: (S[:, 0], S[:, 1:, target_col])) in order to correctly select the target column specified by target_col.

With this modification, the map function will create a new dataset where each element consists of a tuple (S[:, 0], S[:, 1:, target_col]). This means that the first element of the tuple will contain the values from the first column of the input sequence S, and the second element will contain the values from the target column specified by target_col.

Thank you for catching that oversight!

Le sam. 24 juin 2023 à 11:24, slievens @.***> a écrit :

The code for to_seq2seq_dataset is this

def to_seq2seq_dataset(series, seq_length=56, ahead=14, target_col=1, batch_size=32, shuffle=False, seed=None): ds = to_windows(tf.data.Dataset.from_tensor_slices(series), ahead + 1) ds = to_windows(ds, seq_length).map(lambda S: (S[:, 0], S[:, 1:, 1])) if shuffle: ds = ds.shuffle(8 * batch_size, seed=seed) return ds.batch(batch_size)

but this doesn't seem to use the value of target_col. Should it not be

ds = to_windows(ds, seq_length).map(lambda S: (S[:, 0], S[:, 1:, target_col]))

on the second line?

— Reply to this email directly, view it on GitHub https://github.com/ageron/handson-ml3/issues/81, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQWZSO2VKBKJZZEOFAMWG5TXM2547ANCNFSM6AAAAAAZSNX2XY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

anas-2003 avatar Jun 24 '23 11:06 anas-2003