# LSTM Recurrent Neural Network for Hand Gesture Recognition Using EMG Signals
## 2 Methodology
### Metrics  
Once the model is trained, it is important to define a way to determine its performance, this is when performance metrics come to play. There are many metrics to indicate the performance of a model, most of them based on the confusion matrix, which contains the values of true positives (TP), true negatives (TN), false positives (FP) and false negatives (FN), values that come in handy to calculate these metrics.  
This research evaluated the performance of the gesture classifier using two metrics commonly used in the literature [76]. The first one was the accuracy, which can be mathematically defined as shown in Equation (14).  
\[Accuracy=\frac{TP+TN}{TP+TN+FP+FN} \tag{14}\]  
As Equation (14) shows, the accuracy measures how much the model is correctly predicting on the entire data-set and represents the probability that a prediction made by the model is correct. Although this is an easily interpretable measure, it comes with the issue that it does not consider the data-set class distribution and gives the same weight to each prediction, which tends to hide strong classification errors for classes with few examples, since those classes are less relevant compared to the biggest ones, thus, this metric can be easily misinterpreted and give a false sense of performance for the model. This downside in this metric, generally occurs when the model is trained or validated with imbalanced data-sets in which some classes have fewer examples than other classes.  
To solve the aforementioned disadvantage in the accuracy metric, a second metric is proposed that allows to validate the performance of the model; the proposed metric is the Macro F1-Score (multi-class version of the F1-Score), which can be interpreted as a harmonic mean of the model precision and recall. It is important to note that, considering the gesture classifier has multiple classes, it is necessary to average the precision and recall across all classes in order to calculate the Macro F1-Score. Equations (15)-(17) shows the necessary calculations to find the metric.  
\[Precision_{j} =\frac{TP_{j}}{TP_{j}+FP_{j}} \tag{15}\] \[Macro\ Precision =\frac{\sum_{j=1}^{C}Precision_{j}}{C}\] \[Recall_{j} =\frac{TP_{j}}{TP_{j}+FN_{j}}\] (16) \[Macro\ Recall =\frac{\sum_{j=1}^{C}Recall_{j}}{C}\] \[Macro\ F1\text{-}Score =2\left(\frac{Macro\ Precision*Macro\ Recall}{Macro\ Precision+Macro \ Recall}\right) \tag{17}\]  
As Equations (15)-(17) show, the precision and recall are calculated for each class and then averaged across the \(C\) classes of the classifier.  
The Macro F1-Score is useful to support the accuracy metric and validate the model performance even if the data-set is imbalanced. As mentioned earlier, the F1-Score requires the model precision, which is a measure of the model's quality. It indicates if the model returns more relevant predictions (TP) than irrelevant ones (FP); on the other hand, the F1-Score also requires the model recall, which is a measure of the model's quantity. Itindicates the capacity of the model to return most of the relevant predictions (TP) without considering if irrelevant predictions are also returned. With this in mind, the F1-Score, being the harmonic mean between the precision and recall, gives equal weight to both metrics. Thus if the F1-Score is high, both metrics will also be high, more relevant predictions and among all positive predictions most of them are relevant. Moreover, considering that the F1-Score is based on the average metrics for each class, it gives the same weight to all classes, taking them all into consideration independently if some classes have less examples than other classes, thus, giving a better estimate of the model performance.