# Regressive Machine Learning for Real-Time Monitoring of Bed-Based Patients
## 2 Materials and Methods
### Machine Learning  
The methodology involves the application of ensemble ML models on a given dataset [21]. The dataset is first imported into the Python environment (version 3.12) using the pandas library. The dataset is divided into two parts: the input data (X), which consists of all columns except the first one, and the target variable (y), which is the first column. The input data are then normalized to be between 0 and 1 using the MinMaxScaler from the sklearn.preprocessing module. This is conducted to ensure that all input data are on the same scale, preventing the model from being biased towards data with larger scales.  
In our dataset, we observe an imbalance in the distribution of classes within the target variable. This imbalance can potentially lead to a model bias, where the model might overfit to the majority class and underperform when predicting the minority class. To mitigate this issue, we employ the Synthetic Minority Over-sampling Technique (SMOT), which is a technique that generates synthetic data for the minority class, thereby balancing the class distribution. The process of synthetic data generation involves calculating the k nearest neighbors for each instance in the minority class, randomly choosing one of these neighbors, and creating a synthetic instance at a random point on the line segment connecting the two instances. This can be represented by the following formula:  
\[x_{synthetic}=x_{minority}+\lambda\cdot(x_{neighbor}-x_{minority}), \tag{1}\]  
where \(x_{synthetic}\) is the synthetic instance, \(x_{minority}\) is the instance from the minority class, \(x_{neighbor}\) is the randomly chosen neighbor, and \(\lambda\) is a random number between 0 and 1.  
The sampling strategy, to mitigate the imbalance in the dataset, is set such that each class in the target variable has 200 instances. The random state is set to 42 for reproducibility. This is a common practice in ML where a specific seed is set for the random number generator. This allows the results to be reproduced exactly, as the same \"random\" numbers will be generated each time the code is run.  
The data are then split into training and test sets, with 80% of the data used for training and 20% used for testing. The random state is again set to 42 for reproducibility. Several models are then fitted to the training data, including the Decision Tree Regressor, Gradient Boosting Regressor, and Bagging Regressor.  
The methodology diverges from traditional feature selection processes due to the regression-based nature of the model. In contrast to the conventional feature selection methods often employed in classification problems, this study assesses the model's effectiveness based on its precise prediction of movements, using the entire dataset. This dataset is compiled from measurements captured by sensors as a mannequin executed six unique movements along three specific axes: east-west, north-south, and up-down. Consequently, the typical notion of feature selection, frequently observed in classification problems, is not directly applicable in this regression-based scenario. The model's performance is instead evaluated on its capacity to accurately forecast the movements, utilizing the entire dataset.