# Workout Detection by Wearable Device Data Using Machine Learning
## 2 Method
### Data Analysis and Machine Learning Algorithms  
The biometric data collected by the sensor were converted to a CSV file using special software (SilmeePro Wx, manufactured by TDK) and output. The operating system used was Windows 10 (64-bit). Machine learning was performed in Python (3.6.5) with Spyder (editor, 3.2.8) obtained from Anaconda, an open data science platform. We used scikit-learn (0.20.0) as the machine learning library.  
The random forest (RF), support vector machine (SVM, kernel: rbf), and K-nearest neighbor (KNN) algorithms were used as classifiers for machine learning. The number of steps, amount of activity, active type, sleeping position, sleep state, skin temperature, mean pulse rate, UV level, and amount of conversation were used as feature values, and these feature values were extracted every minute. As data pre-processing, if even one of these feature values was missing, the data at that time were regarded as missing and deleted. Since 3416 min of workout data with the measurement accuracy maintained were extracted, the number of nine types of feature values for workout, awake (activities other than workout), and sleep was also adjusted to 3416.  
Detection of workout was evaluated using k-fold cross-validation method. In this study, k = 4 because 75% of the 3416 min of data was training data and 25% was validation data. For the data set, 9 features of workout, wakefulness, and sleep were randomly shuffled and these were prepared for 854 min for each segment. Table 1 shows the hyperparameters used for machine learning. RF's \"n_estimators\" and \"max_depth\" are number of trees and depth of tree, respectively. KNN's \"n_neighbor\" is K value. Other parameters are default values. These hyperparameters are changed by grid search, and the optimal recall, precision, and F-score (harmonic mean of recall and precision) in each segment are calculated by the k-fold cross-validation method. The detection accuracy of the classifier was defined as mean value of 4 segments. Here, recall, precision, and F-score are given by the following Equations (1) to (3), where TP, FP, and FN are the true positive, false-positive, and false negative, respectively. In addition, in order to investigate how much the 9 features contribute to detection in RF, features importance was calculated using the importance function of scikit-learn for each segment.  
\[\text{Recall}=\text{TP}/(\text{TP}+\text{FN}) \tag{1}\]  
\[\text{Precision}=\text{TP}/(\text{TP}+\text{FP}) \tag{2}\]  
\[\text{F-score}=2\times\text{Recall}\times\text{Precision}/(\text{Recall}+ \text{Precision}) \tag{3}\]  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Classifier** & \multicolumn{2}{c}{**Hyperparameter**} \\ \hline RF & n\_estimators & 16, 32, 64, 128, 256, 512, 1024 \\ \cline{2-3}  & max\_depth & 16, 32, 64, 128, 256, 512, 1024 \\ \cline{2-3}  & criterion & gini \\ \hline SVM & C & 0.001, 0.01, 0.1, 1, 10, 100, 1000 \\ \cline{2-3}  & gamma & 0.001, 0.01, 0.1, 1, 10, 100, 1000 \\ \hline KNN & n\_neighbors & 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 \\ \hline n\_estimators: number of trees; max\_depth: depth of tree; n\_neighbor: K value. \\ \hline \hline \end{tabular}
\end{table}
Table 1: Hyperparameters of classifiers for machine learning.