# Seizure Detection in Medical IoT: Hybrid CNN-LSTM-GRU Model with Data Balancing and XAI Integration
## 3 Proposed Seizure Detection for MIoT
### Proposed Model Architecture  
SMOTE or the Synthetic Minority Over-sampling Technique can be said to be an effective algorithm in solving class imbalance issues in EEG data specifically for seizure classification. SMOTE improves the proportion of minorities to majorities in the given dataset by creating realistic synthetic samples rather than repeating the subjects of the minority class. It does so by using the existing samples of the minority class and drawing new points in the feature space defined by these samples. If this technique is utilized when dealing with EEG data, it will prevent the under-representation of seizure-related patterns, improving the efficiency of training the machine to classify both seizure and non-seizure instances thus raising the general classification performance.  
Convolutional Neural Networks (CNNs) are applied due to their unique strength of feature extraction of the raw EEG data. This ability is important in mapping the complex and decorated patterns of the EEG signals associated with seizures, such as identifying some small changes that may be related to seizures. Whereas Recurrent Neural Networks (RNN) called LSTM and GRU are developed to avoid the loss gradient result, these architectures can represent temporal dependencies. Their capability to remember information over long sequences makes them suitable for continuous and time-varying data such as EEG, hence facilitating the monitoring and classification of seizures.  
Our proposed technique is the combination of CNN with LSTM and GRU. The model has two types of inputs with two branches that connect to a final concatenation layer. In the case of the CNN branch, the first layer is an input layer where the dimensions are determined by the training dataset, followed by a 1D convolutional layer that applies the relevant filters to capture and retrieve local structures in EEG data. This is then followed by a MaxPooling layer designed to down-sample the convoluted feature maps or the activations and highlight the most critical features. The features are then flattened, ready for concatenation with the LSTM and GRU feature branches. So, the architecture of the hybrid model is as follows: The CNN branch has 3 Layers (Conv1D \(\sim\) MaxPooling1D \(\sim\) Flatten). It uses ReLU activation in the convolutional layer for non-linearity. The LSTM branch has 1 Layer u which uses ReLU activation in the LSTM layer. The GRU branch has 1 Layer. Similarly to LSTM, ReLU activation is used in the GRU layer. The concatenation layer combines the outputs of CNN, LSTM, and GRU into a single feature vector. The output layer has a dense layer with 1 unit and sigmoid activation for binary classification. The compilation details optimizer is Adam with loss function: binary cross-entropy and metrics are the accuracy.  
The temporal dependencies within the model are managed in the second branch utilizing the LSTM and GRU layers. The LSTM layer is intended to learn the long-term dependencies thanks to its ability to learn sequences with varying complex dynamics. The GRU layer works similarly and is also utilized to learn varying patterns but in a rather more simplified manner. The output features generated from all three branches, the CNN, LSTM, and GRU, are merged through a concatenate layer, thereby allowing the fusion of the selected features collected from the CNN and the other selected features captured from the LSTM and GRU. The concatenated resulting output is further passed to the final dense layer which is fitted with a sigmoid activation function to enable it to perform a binary classification: seizure or no seizure. The construction is undertaken using the Adam optimizer and binary cross-entropy loss as the compilation of the model for 100 epochs.