## 3 Methodology
### Feature Crafting and Machine Learning  
The machine learning pipeline involves computing features from input segments and using them to train a random forest model. This study proposes a set of 150 features from temporal, frequency, and wavelet domains [25; 26]. There are 60 features computed from the time domain, 60 features computed from the frequency domain, and 30 features computed from the wavelet domain covering statistical, amplitude-related, and spectral measures across all three axes of inertial data, i.e., x, y and z axis, as shown in Table 1. Since this study explores 3 different window sizes and 2 different labeling approaches, this will give us 6 (\(2\times 3\)) different datasets of signal segments. Hence, features are computed for each of these 6 datasets. This study used MATLAB R2024a for both signal segmentation and feature computation. Manually crafted features are used for model training and evaluation, which is completed using Anaconda's Python V3.10 distribution, on Jupyter Notebook, with Pycaret (used for model training and testing) and Imblearn (used for implementing random under sampling). Segment-wise features are then labeled for the first stage of the pipeline (movement disorder detection) by consolidating the three anomalies into a single unified anomaly binary label. Afterwards, the data are normalized using the z-score normalization technique, which obtains a mean of all values of 0 with a standard deviation of 1, thus resulting in more accurate and faster convergence. From data exploration, it was found that a class imbalance exists for both stages. For anomalous event detection, this study solved this problem using signal segmentation and segment-level labels, as shown at the top of Figure 3. A similar pattern was observed for movement disorder classification in the raw data points, as shown at the bottom of Figure 3. This occurred because the anomalous segment used for classification did not undergo any labeling techniques. \begin{table}
\begin{tabular}{c c} \hline \hline
**Domain** & **Feature** \\ \hline T & \(\mu=\frac{1}{N}\sum_{i=1}^{N}x_{i}\) \\ T & Median = \(\begin{cases}x_{\left(\frac{N+1}{2}\right)},&\text{if $N$ is odd}\\ \frac{x_{\left(\frac{N}{2}\right)}+x_{\left(\frac{N}{2}+1\right)}}{2},&\text{if $N$ is even} \\ T & \(\sigma^{2}=\frac{1}{N}\sum_{i=1}^{N}(x_{i}-\mu)^{2}\) \\ T & \(\sigma=\sqrt{\frac{1}{N}\sum_{i=1}^{N}(x_{i}-\mu)^{2}}\) \\ T & \(\max(x)\) \\ T & \(\min(x)\) \\ T & \(\arg\max_{i}(x_{i})\) \\ T & \(\arg\min_{i}(x_{i})\) \\ T & \(\text{Skewness}=\frac{1}{N}\sum_{i=1}^{N}\left(\frac{x_{i}-\mu}{\sigma} \right)^{3}\) \\ T & \(\text{Kurtosis}=\frac{1}{N}\sum_{i=1}^{N}\left(\frac{x_{i}-\mu}{\sigma} \right)^{4}-3\) \\ T & \(\text{Entropy}=-\sum_{i}p_{i}\log p_{i}\) \\ T & \(\text{RMS}=\sqrt{\frac{1}{N}\sum_{i=1}^{N}x_{i}^{2}}\) \\ T & \(\text{Energy}=\sum_{i=1}^{N}x_{i}^{2}\) \\ T & \(\text{Power}=\frac{1}{N}\sum_{i=1}^{N}x_{i}^{2}\) \\ T & \(\text{MAD}  
The prepared data are then used to train a random forest classifier (number of trees = 100) for binary classification of the input signal segment as an anomalous one or a normal one (stage 1). This study uses a 10-fold cross validation technique for model training and evaluation. The evaluation parameters include accuracy, recall, precision, F1-score, and confusion matrix. The models underwent initial training with the full feature set, followed by training exclusively on the highest-performing features, aimed at reducing execution time. The top-performing feature for movement disorder detection (AD) and movement disorder classification (AC), using data from the most affected upper limb (GeneActiv Smartwatch), with a window size of 250 and S1 labeling, can be seen in Figure 4. If Stage 1 classifies the input signal segment as an anomalous one, then it passes through the second stage, which predicts the type of anomalies (tremor, dyskinesia, bradykinesia) present in the signal.