# MEMS and IoT in HAR: Effective Monitoring for the Health of Older People
## 5 Data Analysis
### Prediction  
The predictive model used is called \"Random Forest\". This model is based on a supervised learning algorithm and employs a bagging technique that utilizes a collection of decision trees to make predictions. The supervised learning algorithm leverages an ensemble learning method for regression, which combines the predictions from multiple machine learning algorithms to produce more accurate results than any single model. One key benefit of the Random Forest model is its ability to reduce overfitting, a common issue associated with individual decision trees. The model is structured as a series of decision trees, each constructed from a random subset of the training data. Each tree independently predicts outcomes based on another random subset of the data, and the final prediction is determined by a majority vote among all the trees. A critical feature of the Random Forest model is the randomness in selecting attributes for each tree. This randomness decreases the correlation among the trees, improving the overall robustness of the model. The entire process can be broken down into several phases, as follows:  
* Creating subsets. For each node in a tree, a random subset of traits is selected from the original dataset. This subset is typically much smaller than the total number of available features;
* Choosing the best feature. From the randomly selected traits, the feature that best separates the data is determined using a quality measure, such as entropy or the Gini index;
* Repeating the process. This process is repeated for each node in every tree within the forest, ensuring that each tree is constructed using a different subset of characteristics;
* Setting hyperparameters. Before training the model, several important hyperparameters must be configured (see Table 2). The Grid Search technique was employed to identify parameters that optimize model predictions. This process involved defining a grid of parameters and the number of cross-validation folds. The parameters considered were as follows:  
* _n_estimators_, [100, 200,];* max_depth, [None, 10,];
* min_samples_split, [2, 5,];
* min_samples_leaf, [1, 2,];
* max_features, [auto, sqrt]. All possible combinations of these parameters were evaluated. The model was trained and assessed for each combination using cross-validation (\(n=5\)). The combination that resulted in the best performance was selected as the optimal set of parameters. The 'fit' method was used to train the model on each combination of parameters, and a dedicated function was employed to identify the best combination. The model was trained and evaluated five times, using a different portion of the data as the test set. The optimal parameters identified were as follows:  
* \(n\_estimators\), 100;
* max_depth, none;
* min_samples_split, 2;
* min_samples_leaf, 1. The total number of iterations conducted while searching for the optimal parameters was 160, corresponding to the number of combinations specified in the grid. The training phase used 80% of the acquired data. With the next prediction step, the model correctly recognized the four predicted activities. To validate the reliability of the model, the following metrics were derived: accuracy, precision, recall, and F1 (see Table 3). The model can make highly accurate predictions based on these values. The next step is to represent the ROC and AUC curves (Figure 16).