# Efficient Human Activity Recognition Using Machine Learning and Wearable Sensor Data
## 2 Data Collection and Preprocessing
### Data Preprocessing
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Classification** & **Acceleration\_x (g)** & **Acceleration\_y (g)** & **Acceleration\_z (g)** \\ \hline \multirow{8}{*}{maximal value} & 5.9232 & 1.7081 & 0.7112 \\  & 1.0570 & 0.3659 & 0.1371 \\  & 1.0503 & 0.5287 & 0.1264 \\  & 2.5574 & 0.7060 & 0.6060 \\  & 1.1602 & 0.3406 & 0.1417 \\  & 2.3480 & 0.6119 & 0.5506 \\  & 2.7744 & 0.7673 & 0.6315 \\ \hline \multirow{8}{*}{minimum value} & \(-0.7350\) & \(-1.3895\) & \(-1.1879\) \\  & 0.8099 & \(-0.0577\) & \(-0.1625\) \\ \cline{1-1}  & 0.8645 & \(0.0327\) & \(-0.1666\) \\ \cline{1-1}  & 0.1645 & \(-0.7742\) & \(-1.0301\) \\ \cline{1-1}  & 0.8099 & \(0.1085\) & \(-0.0428\) \\ \cline{1-1}  & 0.0923 & \(-0.8433\) & \(-1.1731\) \\ \cline{1-1}  & \(-0.0451\) & \(-1.0783\) & \(-1.0961\) \\ \hline \hline \end{tabular}
\end{table} 
Table 2: The extracted number of features in the partial time domain. Table 2 shows some data on the maximum and minimum values of the acceleration on the X, Y, and Z axes obtained from the accelerometer and gyroscope. These data will be used as time-domain features for the recognition of subsequent activities. After that, the similarity between the data points was calculated using Mahalanobis distance. The closer the distance, the higher the similarity between the points. Therefore, we took the reciprocal of the Mahalanobis distance as the measure of similarity and constructed a 60 \(\times\) 60 matrix to store the data. Mahalanobis distance is a metric used to measure the distance between data points, and it is particularly useful in high-dimensional spaces. Unlike Euclidean distance, Mahalanobis distance accounts for the covariance structure of the data, making it more robust to correlations and varying scales of the features [19]. Given a data point, the mean vector, and the covariance matrix of the dataset, the Mahalanobis distance is defined as follows:  
\[D_{M}(x,\,\mu)=\sqrt{(x-\mu)^{T}S^{-1}(x-\mu)} \tag{2}\]  
where \(x\) is the data point to be measured, and \(\mu\) is the mean vector of the data. \(S\) is the covariance matrix of the data, and \(S^{-1}\) is the inverse of the covariance matrix. The covariance matrix \(S\) describes the correlation between the features of the data and the variance of each feature. The elements on the diagonal represent the variance of the individual features, while the off-diagonal elements represent the covariance between different features. The inverse covariance matrix \(S^{-1}\) adjusts for the correlations between the features, allowing the Mahalanobis distance to appropriately account for differences in scale and correlations, thus accurately measuring the distance between the features [20]. To validate the effectiveness and accuracy of the majority decision model based on multiple machine learning algorithms, we adhered to strict statistical principles and scientifically divided the dataset into a training set, a test set, and a validation set at a ratio of 70:20:10. The following two models were performed based on the above datasets.