0
$\begingroup$

I am building a model for the purpose of forcasting when someone is going into a stressful state.

I am using the WESAD dataset which has electrodermal activity (EDA) data on 11 subjects. I take this and use Neurokit2 to clean and extract features from the raw EDA data. The end result is that I have a list that stores each subject in the original dataset with 3 features and 1 label. The label is binary [0,1] and the features are normalized.

I only have experience running a timeseries model using a single factor and single subject. How would I correctly do the train-test split for multiple features on multiple subjects? Below is my code to create data generators for neural networks on one feature and one subject. Should I loop through each subject and do the same process as below? If I do as I suggest, how would I put this into a LSTM model?

from keras.preprocessing.sequence import TimeseriesGenerator

# Define the batch size
batch_size = 64
# Define the number of features and targets
num_features = 1
num_targets = 1
# Random State
random_state = 42
    
# Train Test Split
from sklearn.model_selection import train_test_split

# Validation split
X_dat, X_val, y_dat, y_val = train_test_split(subsampled_data, delayed_labels, 
                                                 test_size = 0.2,
                                                 random_state=random_state)
# Train test split
X_train, X_test, y_train, y_test = train_test_split(X_dat, y_dat,
                                                    test_size = 0.2,
                                                    random_state = random_state)


# Normalize the data
from sklearn.preprocessing import StandardScaler
# create the StandardScaler object
scaler = StandardScaler()
# fit the scaler on the training data
X_train_scaled = scaler.fit_transform(X_train.values.reshape(-1,1))
# transform the validation data
X_val_scaled = scaler.transform(X_val.values.reshape(-1,1))
# transform the test data
X_test_scaled = scaler.transform(X_test.values.reshape(-1,1))

# TimeSeriesGenerator parameters
shuffle = True

# Data Generator
train_data_gen = TimeseriesGenerator(X_train_scaled, y_train, 
                                     length=sequence_length, 
                                     batch_size=batch_size)
val_data_gen = TimeseriesGenerator(X_val_scaled, y_val, 
                                   length=sequence_length, 
                                   batch_size=batch_size)
test_data_gen = TimeseriesGenerator(X_test_scaled, y_test, 
                                    length=sequence_length, 
                                    batch_size=batch_size)
$\endgroup$

1 Answer 1

1
$\begingroup$

Scikit-learn's model_selection.TimeSeriesSplit is designed to appropriately split time series data. The result will include indices that can be used to reference the features, no matter how many features there are.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.