# Gait Phase Identification and Damping Control for Knee Orthosis Using Time Series Forest Classifier
## 4 Machine Learning Algorithm for Gait Phase Identification: Training, Evaluation, and Results
### Lstm-Fcn Classifier  
[PERSON] et al. [24] used a fully convolutional network (FCN) in conjunction with LSTM, which resulted in significant improvement in the time series classification of multivariate data. The major concern with LSTM-FCN architecture (Figure 18 and Table 12) is to have a tradeoff between computational complexity and required accuracy. The number of seven classes is fixed and the length of time series data can be varied. The model has 267,496 parameters, of which 266,472 are trainable and 1024 are nontrainable. They are associated with the convolutional and normalization layers, the weights of which are desired to be pivoted. The model performed better than ROCKET and KNTSC, but the precision and recall for the fifth class were still very poor. The accuracy converged to a value of 0.78, and further change in the LSTM size and other parameters did not result in significant improvement in the results. The large parameters and complex architecture make LSTM-FCN for this application not suitable for deployment. The performance of this classifier is shown in Figure 19, Table 13.  
Table 14 presents a comprehensive overview of the performance of the time series classifiers. Among them, the time series forest classifier (TSFC) stands out as the most suitable choice for gait identification applications, boasting an impressive accuracy of 0.86. The TSFC classifier exhibits notable precision and recall rates, accompanied by a respectable F1-score, thereby demonstrating its efficacy in accurately classifying gait patterns while minimizing false positive results. It is worth noting that class 5, characterized by the lowest percentage of gait samples at a mere 5%, is associated with a limited number of data samples due to the constrained data transfer baud rate of 115,200. Consequently, the fifth gait class consists of only a small number of samples, typically in the range of tens. This scarcity of data adversely affects the classification performance, as evidenced by the ROCKET and K-NTSC classifiers, both of which yield absolute scores of 0 for precision, recall, and F1-score. Consequently, these classifiers are deemed unsuitable for practical usage. The misclassification of class 5 in random forest to class 6 could be potentially tolerated for system deployment, as the difference in the activation level of knee moment associated with these two for normalized value is 0.026, obtained from Table 5. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Class** & **Precision** & **Recall** & **F1-Score** & **Support** \\ \hline
0 & 0.35 & 0.55 & 0.43 & 584 \\
1 & 0.80 & 0.88 & 0.84 & 715 \\
2 & 0.92 & 0.85 & 0.89 & 3262 \\
3 & 0.73 & 0.77 & 0.75 & 759 \\
4 & 0.86 & 0.77 & 0.81 & 894 \\
5 & 0.38 & 0.10 & 0.15 & 493 \\
6 & 0.78 & 0.88 & 0.83 & 2476 \\
7 & 0.76 & 0.71 & 0.74 & 817 \\ \hline Accuracy & & & 0.78 & 10,000 \\ Macro Average & 0.70 & 0.69 & 0.68 & 10,000 \\ Weighted Average & 0.79 & 0.78 & 0.78 & 10,000 \\ \hline \hline \end{tabular}
\end{table} 
Table 13: Evaluation metrics for LSTM–FCN. Figure 19: Confusion matrix for LSTM–FCN classifier. Comparing LSTM-FCN and TSFC, it is evident that TSFC achieves higher performance scores and exhibits computational feasibility during training, as well as ease of deployment. However, in class 0, which encompasses non-gait-related data such as stationary conditions and abnormal activities, LSTM-FCN slightly outperforms TSFC. This marginal advantage of LSTM-FCN in class 0 can be attributed to its enhanced ability to extract relevant features from the data. A single gait cycle typically has an average duration of 0.98 to 1.02 s. Phase 5 therefore averages approximately 50 milliseconds. Given the computations performed by the IMU and the limited 115,200 baud rate for UART data transfer, the output data range from 2 to 15 data points per gait cycle. This imbalanced dataset cannot be equalized using conventional methods such as undersampling, oversampling, or ensembling. Therefore, class weighting is applied by assigning a higher weight to the class with fewer samples.