Leave-One-Subject-Out Cross-Validation (LOSV) for DGCNN Model in SEED Dataset
Pseudo code for the given code in English:
Define a function 'main_LOCV()':
-
Set the directory path as 'D:/SEED/SEED/SEED_code/DE/session1/'.
-
Get the list of files in the directory and store the number of files in 'sub_num'.
-
Define the dimensions of the input tensor as 'xdim = [128, 62, 5]'.
-
Set the value of 'k_adj' as 40, 'num_out' as 64, 'num_epochs' as 5, 'acc_mean' as 0 and 'acc_all' as an empty list.
-
For each 'sub_i' in the range of 'sub_num':
-
Set the 'load_path' as the directory path concatenated with the file name.
-
Load the data and labels from the file using the 'load_DE_SEED' function.
-
Normalize the data using the 'zscore' function.
-
Initialize a 'DGCNN' model with 'xdim', 'k_adj' and 'num_out' and move it to the device.
-
Define the loss function as 'CrossEntropyLoss'.
-
Define the optimizer as 'Adam' with learning rate 0.001 and weight decay 0.0001.
-
Define the 'train_list' as a deep copy of 'file_list' and remove the current file from it.
-
Set 'train_num' as the length of 'train_list'.
-
For each 'train_i' in the range of 'train_num':
- Set 'train_path' as the directory path concatenated with the file name.
- Load the data and labels from the file using the 'load_DE_SEED' function.
- Normalize the data using the 'zscore' function.
- Concatenate the data and labels to 'data_train' and 'label_train' respectively.
- Convert 'data_train' and 'label_train' to tensors.
-
Load the training and testing data using the 'load_dataloader' function.
-
Train the model using the 'train' function and get the best testing accuracy.
-
Update the value of 'acc_mean' as 'acc_mean' plus 'acc_test_best/sub_num'.
-
Append the value of 'acc_test_best' to 'acc_all'.
-
-
Save the values of 'acc_all' and 'file_list' as a MAT file.
-
Print the LOSV test accuracy, mean accuracy and standard deviation of accuracy from 'acc_all'.
原文地址: https://www.cveoy.top/t/topic/nHOg 著作权归作者所有。请勿转载和采集!