# Efficient Human Activity Recognition Using Machine Learning and Wearable Sensor Data
## 3 Methods
### Classification Model Based on Machine Learning
Each time, the dataset is randomly selected with replacement, and at the same time, some features are randomly chosen as input. This is why the algorithm is called the Random Forest algorithm. The foundation of Random Forest lies in decision trees, which are tree-like models used for classification or prediction based on feature values. Each internal node represents a test on a feature, each branch represents the outcome of the test, and each leaf node represents the classification result or numerical prediction. Random Forest is an ensemble learning method that improves the performance of a single model by combining the predictions from multiple models. It achieves this by creating multiple decision trees [26]. The randomness in Random Forest includes both sampling randomness and feature randomness. The former refers to using bootstrap sampling to randomly select different subsets of the original data to train each decision tree. The latter refers to randomly selecting a subset of features at each decision node to determine the best split, which reduces the correlation between the trees. * Problem-solving steps based on Random Forest are as below:
* Data Preparation: clean and preprocess the data to ensure there are no missing values and outliers. * Construct training set and test set: divide the dataset into a training set and a test set to evaluate the performance of the model. * Generate decision trees: randomly select multiple subsets from the training set. Train a decision tree for each subset. When building each tree, randomly select a subset of features at each node and choose the best split point based on these features. * Ensemble decision trees: integrate the prediction results of all decision trees. For classification problems, determine the final category through a voting mechanism; for regression problems, usually take the average of the predictions of all trees. * Model evaluation: use the test set to evaluate the model performance, including metrics such as accuracy, precision, and recall rate. * Tuning and optimization: adjust the hyperparameters of the Random Forest, such as the number of trees, the maximum depth of each tree, the minimum number of samples for splitting, etc., to improve the model performance. * The main advantages of Random Forest lie in its strong generalization ability and low overfitting risk, making it suitable for handling large-scale datasets and complex problems. During the training process for machine learning, we used a carefully curated and diverse dataset that was capable of representing a wide range of human activities and scenarios. This dataset was divided into a training set, a validation set, and a test set. The division process was random and stratified to ensure that each category of human activities was proportionally represented in all subsets. This approach helps to reduce bias, as the data distribution that the model is exposed to during training is balanced. For validation, we monitored the performance of the model on the validation set after each training cycle. If the performance on the validation set starts to decline while the performance on the training set continues to improve, this is a sign of overfitting. In such cases, we will adjust the hyperparameters of the model. For testing, we used the held-out test set, which the model has never encountered during the training or validation period. This provides an unbiased estimate of the model's generalization ability. The final performance of the model is reported based on the results obtained from the test set. Therefore, through appropriate data partitioning and performance monitoring, we have effectively reduced the risks of overfitting and bias in the machine learning model, thus enhancing the model's generalization ability in real-world scenarios. Subsequently, we processed the training set using the aforementioned model and established a machine learning decision-making model for 12 types of human activities.