# Robust IoT Activity Recognition via Stochastic and Deep Learning
## 6 Experimental Results and Analysis
### Model Training and Performance Evaluation  
For pattern recognition, we implemented a comprehensive suite of eight classifiers, including both traditional machine learning algorithms (SVM, Decision Tree, and Random Forest) and advanced deep learning architectures (CNN, LSTM, Transformer, Swin Transformer, and TransUNet). This expanded model comparison addresses previous limitations in the literature regarding Transformer-based architectures and provides a more complete assessment of state-of-the-art approaches. To better suit our HAR task, we adapted the SwinTransformer by adjusting its window-based attention mechanism to align with temporal sensor data segments. Additionally, we modified the TransUNet structure by simplifying the encoder-decoder design for improved efficiency in time series feature extraction. All models were trained on consistently preprocessed data to ensure fair comparison. Table 4 presents the classification performance across all evaluated models, with Random Forest achieving the highest accuracy (98.91%), followed closely by TransUNet (91.30%) and Decision Tree (89.13%). To ensure statistical rigor, we implemented 5-fold cross-validation and conducted ANOVA testing (\(F=48.69\), \(p<0.001\)), confirming that performance differences between models are statistically significant. Subsequent pairwise t-tests further elucidated specific inter-model differences (Figure 8), with Random Forest significantly outperforming most other models (\(p<0.05\)) except TransUNet (\(t=0.04\), \(p=0.97\)), with which it showed comparable performance. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Model Category** & **Model** & **Accuracy** & **Cross-Val Mean (SD)** \\ \hline \multirow{3}{*}{Traditional ML} & SVM & 72.83\% & 73.37\% (\(\pm\)2.92\%) \\  & Decision Tree & 89.13\% & 84.51\% (\(\pm\)4.48\%) \\  & Random Forest & 98.91\% & 89.66\% (\(\pm\)4.73\%) \\ \hline \multirow{3}{*}{Deep Learning} & CNN & 79.35\% & 87.12\% (\(\pm\)1.33\%) \\  & LSTM & 85.87\% & 81.41\% (\(\pm\)1.74\%) \\ \cline{1-1}  & Transformer & 65.22\% & 60.49\% (\(\pm\)1.99\%) \\ \cline{1-1}  & Swin Transformer & 82.61\% & 83.10\% (\(\pm\)1.52\%) \\ \cline{1-1}  & TransUNet & 91.30\% & 89.57\% (\(\pm\)1.38\%) \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Comprehensive performance comparison across machine learning and deep learning models. Figure 7: Fourier transform plots of the raw, low-pass filtered, high-pass filtered, and Kalman filtered accelerometer data along the x, y, and z axes during running, demonstrating the superior noise reduction capability of the optimized Kalman filter. Figure 9 illustrates the classification performance of each model through confusion matrices. The visualization reveals that Random Forest achieved the most balanced classification across all three activities, with minimal misclassifications between classes. Random Forest correctly classified 25 of 27 running instances, all 19 squatting instances, and all walking instances. The TransUNet model showed similarly strong performance, particularly for running activities (26 of 27 correct), demonstrating the potential of hybrid architectures that combine convolutional features with Transformer-based attention mechanisms. Figure 8: Statistical tests. Figure 9: Confusion matrices for different models showing the distribution of true vs. predicted classes across the three activities (Running, SquatStand, Walking). The training dynamics of deep learning models are visualized in Figure 10, which plots the training and validation accuracy across epochs. The TransUNet model demonstrated the strongest learning progression, achieving a peak validation accuracy of 90.54% at epoch 29. The LSTM and Swin Transformer models showed competitive performance (peak validation accuracies of 89.19% and 89.19%, respectively). In contrast, the standard Transformer model exhibited considerably more modest improvements, with validation accuracy plateauing around 66.22%, suggesting particular challenges in capturing relevant temporal patterns with limited training data.