df = df_1.iloc[0:200000, :]

# Train-Test Split (keeping all columns)
train, test = df.loc[df['index'] <= 160000], df.loc[df['index'] > 160000]

# Create a StandardScaler object and fit on the first 21 columns of the training data
scaler = StandardScaler()
scaler = scaler.fit(train.iloc[:, 0:21])

# Transform the first 21 columns of both training and test data
train.iloc[:, :21] = scaler.transform(train.iloc[:, :21])

test.iloc[:, :21] = scaler.transform(test.iloc[:, :21])


seq_size = 3
def to_sequences(x, y, seq_size):
    x_values = []
    y_values = []

    for i in range(len(x) - seq_size):
        x_values.append(x.iloc[i:(i + seq_size), :21].values)
        y_values.append(x.iloc[(i + seq_size), :21].values)

    return np.array(x_values), np.array(y_values)

trainX, trainY = to_sequences(train[["Fp1", "Fp2", "F3", "F4", "F7", "F8", "Fz", "C3", "C4", "Cz", "T3", "T5", "T4", "T6", "P3", "P4", "Pz", "O1", "O2", "ECG", "Resp"]], train['y'], seq_size)

testX, testY = to_sequences(test[["Fp1", "Fp2", "F3", "F4", "F7", "F8", "Fz", "C3", "C4", "Cz", "T3", "T5", "T4", "T6", "P3", "P4", "Pz", "O1", "O2", "ECG", "Resp"]], test['y'], seq_size)

model = Sequential()
model.add(LSTM(128, input_shape=(trainX.shape[1], trainX.shape[2])))
model.add(LSTM(128, return_sequences=True))
model.[![enter image description here][1]][1]add(Dropout(rate=0.2))
model.add(TimeDistributed(Dense(trainX.shape[2])))  # This output same shape as the input 
model.add(TimeDistributed(Reshape((1, 21))))
model.compile(optimizer='adam', loss='mean_absolute_error')


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.