How should I reshape my data to feed for torch LSTM model?

36 views Asked by At

I have an excel sheet contains time sequences data: each row contains 13 variables('timestamp', lane1 speed deviation', 'lane1 headway', 'lane1 volume' ,'lane 1 truck share',...etc.) and 1 label('lane 1 speed')

What I want to do is predict 'lane 1 speed' on the 4th time interval based on 3 sets of historical data.

For example: predict 'lane 1 speed' on '2023-11-15 15:45' based on 13 variables on '2023-11-15 15:00', '2023-11-15 15:15' and '2023-11-15 15:30'.

I don't know how to reshape these data and feed for torch LSTM input? I seached the LSTM document, it says the input data shape should be like :(batch_size, time_steps, seq_len), so I assume my time_steps are 3? and seq_len is 13?

I tried to create a function in python:

def split_sequence(data,label, n_steps):
    # X, y = list(), list()
    X, y = [], []
    for i in range(len(data)):
        end_ix = i + n_steps #例如4,5,6
        if end_ix +1 > len(data):
            break
        seq_x, seq_y = data[i:end_ix,:], label[end_ix]   #
        X.append(seq_x)
        y.append(seq_y)
    return np.array(X),np.array(y)
print(f"data_seq size:{data_seq.shape}")

print(f"label_seq size:{label_seq.shape}")

output:

data_seq size:(701, 3, 13)

label_seq size:(701, 1)

Is it correct? Thank you all

data for training and prediction

0

There are 0 answers