# Efficient Human Activity Recognition Using Machine Learning and Wearable Sensor Data
## 3 Methods
### Classification Model Based on Machine Learning  
There are many machine learning algorithms. The following are some of the typical ones involved in this work. SVM (Support Vector Machine)  
SVM is a class of dichotomy model with supervised learning. Compared with logistic regression and neural network, SVM provides a clearer and powerful way when learning complex nonlinear equations, whose essence is to find the optimal classification hyperplane in the feature space [22]. \[H_{0}:\ w\cdot x+b=0, \tag{7}\]  
\[H_{1}:\ w\cdot x+b=-1, \tag{8}\]  
\[H_{2}:\ w\cdot x+b=1, \tag{9}\]  
\(H_{0}\) is the optimal classification hyperplane to be determined. The hyperplane \(H_{1}\) and \(H_{2}\) are both parallel to \(H_{0}\) and at an equal distance, dividing the two sides of \(H\); the points on \(H_{1}\) and \(H_{2}\) are the sample points closest to \(H_{0}\), and their geometric distance to \(H_{0}\) is \(1/\|w\|\). This paper uses a Nonlinear Support Vector Machine (SVM) to address complex nonlinear separable problems. When the sample space of the training set is nonlinearly separable, it indicates that the data are linearly inseparable in the original (low-dimensional) space. In such cases, the training set can be mapped from the original space to a higher-dimensional feature space, making the test set linearly separable in the high-dimensional space. However, directly performing classification in the high-dimensional space presents challenges, such as determining the form and parameters of the nonlinear mapping function. Additionally, operations in high-dimensional spaces are computationally intensive, and the results may not always be ideal. \[k\big{(}x_{i},x_{j}\big{)}=\Big{(}x_{i}^{T}x_{j}\Big{)}^{d}, \tag{10}\]  
A kernel function can map the raw input data from a low-dimensional space to a high-dimensional space, where the data may become linearly separable, as shown in Equation (10). In this case, we have chosen a polynomial kernel function of degree 3 [23]. By using the kernel function, we effectively transform the dot product operation in the high-dimensional space into an operation in the lower-dimensional input space, allowing us to efficiently solve the problem and find the optimal hyperplane in the high-dimensional space. The k-nearest neighbor algorithm (KNN)  
KNN is a supervised learning algorithm with labels. Distance metric, the selection of \(k\) value, and classification decision rules are the three basic elements of KNN. When we input the test set, the output is the corresponding label of the test set. Based on this algorithm, we mainly constructed three discrimination models, namely 1-nearest neighbor algorithm, 5-nearest neighbor algorithm, and 12-nearest neighbor algorithm [24]. The distance metric is defined as below:  
\[L_{p}\big{(}x_{i},x_{j}\big{)}=\left(\sum_{l}^{n}\Big{|}x_{i}^{(l)}-x_{j}^{(l )}\Big{|}^{p}\right)^{\frac{1}{p}}, \tag{11}\]  
Here, let \(p\) = 2 correspond to the Euclidean distance. The selection of \(k\) is crucial. If \(k\) is too small, the classification result can be easily influenced by noisy points. If \(k\) is too large, the nearest neighbors may include too many points from other categories. Typically, \(k\) is an integer not greater than 20. In practice, we usually select the first \(k\) most similar data points from the training set and classify the new data based on the most frequent category among these \(k\) nearest neighbors [25]. The 1-nearest neighbor algorithm is the most commonly used. Additionally, since each experimenter has five sets of data for each activity state, the 5-nearest neighbor algorithm is also employed. Given that there are 12 activity states, the 12-nearest neighbor algorithm is also applied. Finally, the classification decision rule for KNN involves taking the input sample point from the test set as the center and determining its category based on the categories of the \(k\) nearest training sample points, which is similar to our subsequent majority decision model. In Random Forest, multiple decision trees are combined.