# Forward Fall Detection Using Inertial Data and Machine Learning
## 3 Development of the Fall Detection Models
### Training the LSTM Neural Network  
One kind of recurrent neural network (RNN) is an LSTM network (LSTM). Because LSTMs can recognize long-term connections between data time steps, they are mostly utilized for learning, processing, and the classification of sequential data. The LSTM neural network is developed using MATLAB's Deep Learning Toolbox [28]. The data is split into train, test, and validation sets, where 70% of the data is used for training the model, 15% for testing and 15% for validation. The neural network is set to accept sequences with input size features of 2, consisting of acceleration data on the X and Y axes. The network's architecture contains an LSTM layer with 512 hidden units, designed to capture temporal dependencies in sequence data and a fully connected layer that maps the LSTM output to the desired number of responses, which is set to 1. A dropout layer which randomly sets 20% of the input units to zero at each update during training is set, which helps prevent overfitting. A regression layer is used to compute the mean squared error loss. Even though the task involves classifying data into three distinct classes, we have opted for a regression approach because the model doesn't treat the classes as completely distinct entities, but rather learns to predict a continuous value that reflects the inherent ordering of the classes. Using regression allows the model to make more nuanced predictions, which can be converted to class labels later. To train the network, the Adam optimization algorithm is used, and the number of training epochs is set to 1000, the gradient threshold to 0.001, and the initial learning rate to 0.0001. The training data is shuffled by batches of 60 samples. The number of samples per batch is chosen empirically for graphical visualization purposes. This approach means that instead of shuffling individual samples randomly, we shuffle predefined chunks (batches) of data by applying shuffled indices. During the training, the networks' performance is evaluated by plotting the root mean squared error (RMSE), as shown in Figure 12, and the Loss curve, as shown in Figure 13.  
Figure 12: Plotted RMSE curve. The root mean squared error (RMSE) is a metric commonly used to evaluate the performance of regression models. It is the square root of the mean squared error, as shown in Equation (3). \[RMSE=\sqrt{\frac{1}{n}\sum_{i=1}^{n}{(y_{i}-\hat{y}_{i})^{2}}} \tag{3}\]  
where \(y_{i}\) is the actual values and \(\hat{y}_{i}\) is the predicted values. The term \"loss\" refers to the value given by the loss function, which measures the difference between the predictions and the actual target values. For the network to correspond to the best validation loss, we have adjusted the training options to keep track of the best validation model. MATLAB's trainingOptions allows us to use the ValidationPatience option to stop training early if the validation loss does not improve after 50 validations by enabling OutputNetwork to 'best-validation-loss'. As observed in Figures 12 and 13, the loss value is around 0.1, and the validation RMSE is around 0.3, suggesting that the LSTM model achieves a low average relative error in the predicted values. While the value of RMSE indicates a good general performance, it does not guarantee that all predictions are within a 30% deviation of the true values, thus, in the next section, the LSTM network is also tested using unseen experimental data. The network undergoes an initial evaluation to assess its performance on unseen data by plotting the Predicted vs. Original graph in Figure 14, while considering the 15% which represents unseen test data from a total of 17,220 samples. The plots that are red lines with an asterisk are the predicted values and the plots in green are the actual test values. Figure 14: Testing performance of the trained LSTM network. Figure 13: Plotted Loss curve.