# 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
### Time Series Forest Classifier (TSFC)
#### 4.1.3 Maximum Depth  
The value for the maximum depth was chosen to be 10. This provides optimal performance in this application. Higher depth helps to capture the more intricate relationship of orientation data but increases the risk of overfitting. Given the variation in data, a tradeoff is achieved by avoiding the overfitting of the model. The performance of the time series forest classifier (Figure 12) is evaluated with 1000 support variables associated with the right leg. Figure 13 shows the corresponding confusion matrix of the true and predicted classes. \begin{table}
\begin{tabular}{c c} \hline System RAM & 12 GB \\ System storage & 78.2 GB \\ GPU NVIDIA Tesla T4 & 16 GB GDDR6 \\ Cores & 2560 \\ Bus width & 256 bits \\ \hline \end{tabular}
\end{table} 
Table 6: System and GPU specifications. The overall accuracy of the model is 0.86 for support of 1000 occurrences in the class. The weighted average precision is 0.86. Recall is 0.86 and F1-score is 0.86, as shown in Table 7. The recall and F1-score of class 5 are very poor, which can be attributed to the minuscule number of data points associated with its 5% gait percentage share, as shown in Figure 9. Class 0 corresponds to all the activities that are irrelevant during dataset creation with no activation required. In Figure 14, the importance of each feature is represented by corresponding to the effect it has in the decision tree during the selection of decision boundaries and classification. Here, the R2, which is associated with the \"roll\" of IMU mounted on the shin, affects the decision making twice as much in comparison to the roll of IMU mounted on the thigh. The \"yaw\" values are marginally insignificant for any decision making and can be corroborated with physical play of the leg where gait causes insignificant locomotion in the frontal plane. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Class** & **Precision** & **Recall** & **F1-Score** & **Support** \\ \hline
0 & 0.39 & 0.47 & 0.42 & 15 \\
1 & 0.86 & 0.86 & 0.86 & 71 \\
2 & 0.96 & 0.94 & 0.95 & 332 \\
3 & 0.86 & 0.92 & 0.89 & 107 \\
4 & 0.90 & 0.94 & 0.92 & 87 \\
5 & 0.71 & 0.16 & 0.26 & 64 \\
6 & 0.78 & 0.94 & 0.85 & 230 \\
7 & 0.87 & 0.82 & 0.84 & 94 \\ \hline Accuracy & & & 0.86 & 1000 \\ Macro Average & 0.79 & 0.76 & 0.75 & 1000 \\ Weighted Average & 0.86 & 0.86 & 0.86 & 1000 \\ \hline \hline \end{tabular}
\end{table} 
Table 7: Evaluation metrics for time series forest classifier. Figure 12: Time series forest classifier architecture. Figure 13: Confusion matrix for time series forest classifier. The correlation matrix in Figure 15 provides valuable insights into the relationships between all the variables within the dataset. The correlation coefficient for the model output ranges from \(-1\) to \(+1\) and quantifies the degree of correlation, where values close to \(-1\) indicate a strong negative correlation, values close to \(+1\) indicate a strong positive correlation, and values near 0 imply no correlation. Strong positive correlations among R1 and R2 depicting the roll of IMUs 1 and 2 suggest that as one variable increases, the other tends to increase as well, which is physically evident as gait involves flexion of the knee in conjunction with two IMUs. A similar trend is observed for the pitch and yaw associated with both IMUs. Also, there is a positive correlation, 0.4, of R1 (roll of IMU1) with Z22 (acceleration along Z direction for IMU2), indicating an accelerated movement of the shin (IMU2) when the thigh (IMU1) has increased in roll value along the sagittal plane. Strong negative correlations imply an inverse relationship, which can be seen for R1 and P1; these two are independent of each other to a large extent, with a value of \(-0.65\). This information is crucial for feature selection, as highly correlated variables may provide redundant or overlapping information, and for this application. Figure 14: Visualization of important features. Figure 15: Correlation matrix for various features.