Real-Time Risk Assessment Detection for Weak People by Parallel Training Logical Execution of a Supervised Learning System Based on an IoT Wearable MEMS Accelerometer

Activity monitoring has become a necessary demand for weak people to guarantee their safety. The paper proposed a Parallel Training Logical Execution (PTLE) system using machine learning (ML) models on a microelectromechanical system (MEMS) accelerometer to detect coughs, falls, and other normal activities. When there are many categories, the ML prediction can be confused between these activities with each other. The PTLE system trains several models in parallel with more specific activity classes in each dataset. The shared tasks between parallel models relieve the complexity for a single one. There are six additional parameters for accelerometer characteristics, which were calculated from three axes accelerations as input features to improve the ML’s consciousness. Once all models were trained, the system was ready to receive the input accelerations and activated the logical flow to manage link operation between these ML models for output predictions. Random Forest (RF) had the highest potential among the ML classification algorithms after the validation. In the experiment, the comparison between the PTLE model and the regular ML model were carried out with real-time data from an M5stickC wearable device on the user’s chest to the trained models on PC. The result showed the advancement of the proposed method in term of precision, recall, F1-score with an overall accuracy of 98% in the real-time test. The accelerations from the wearable device were sent to ML models via Wi-Fi with Message Queue Telemetry Transport (MQTT) broker, and the activity predictions were transferred to the cloud for the family members or doctor care based on Internet of Things (IoT) communication.


Introduction
Nowadays, many frailty/old people need to be under health monitoring at home. Activity recognition is an important aspect of context-aware systems. Cough and falls are two of the most anxious events which need to be detected for health's sake. Cough is a symptom of many types of flu or coronavirus disease 19 (COVID-19) [1]. Suppose a coughing fit is severe or lasts for an extended period. In that case, components of the respiratory system and other body areas can be damaged, such as blood vessels, chest or muscle pain, etc. [2]. Falls typically occur unexpectedly while performing daily activities and are a health threat, especially for adults of age 65 and older [3]. Other daily activities such as sitting, walking, and sleeping can also be monitored to understand the typical behaviors of weak people.
The MEMS accelerometer [4][5][6] has a high potential capacity to support activity classifications. The accelerations on the X-axis, Y-axis, and Z-axis vary depending on body movement, which can be a key factor in providing valuable information for action recognition. There are articles that research accelerometers in human activity recognition (HAR) by deep learning (DL), a subset of ML. In the paper [7], the research focused on a hybrid • Xacc, Yacc, and Zacc are the acceleration of the X-axis, Y-axis, and Z-axis, respectively. • ∆Xacc, ∆Yacc, and ∆Zacc are the absolute difference values between two consecutive samples of the X-axis, Y-axis, and Z-axis, respectively. • ∆acc_Norm is the magnitude normalization of ∆ acceleration. • ∆Roll and ∆Pitch Zacc are the absolute difference values between two consecutive samples of roll and pitch, respectively.
After validation, the RF algorithm accomplished the best accuracy score among the used algorithms, so it was implemented into the ML models.
With the support of IoT [16], the accelerations from the wearable device on the chest were transferred to the ML models via MQTT broker based on Wi-Fi. Then, ML predictions were sent to the IoT dashboards for healthcare monitoring by family members or doctors.
The paper is organized as follows: the first part briefly describes the regular ML model. The following parts discuss the PTLE system in terms of training process and logical execution. In the experiment, a real-time comparison between the regular model and the PTLE technique was performed regarding precision, recall, F1-Score, and accuracy. Finally, the conclusion summarizes the work's achievements and future proposals.

Related Work
The PTLE contains the ML models that enable a new approach to utilize various ML algorithms in one method. A published article [17] discussed a parallel architecture to combine traditional and deep learning pattern classification algorithms, for accrued computational and classification accuracy, as an ensemble learning architecture. Generally, Sensors 2023, 23, 1516 3 of 14 the authors used three pipelines to obtain a prediction vector for the same training dataset. The final classification result was based on the majority voting for decision fusion. This work still requires the convolutional neural network (CNN), the multivariate time series classification task, which considerably increases the complexity of the system with highcost computation/design for the convolution layer and the pooling layer. This approach constitutes a long training time with the large number of weight updates and two other models for the same amount of training data and same classification number.
MEMS accelerometers [18][19][20][21] have played an essential role in the HAR due to their well-integrated capability inside wearable devices. The acceleration data demonstrate the corresponding fluctuation with the human motion that is extremely useful to combine with the ML approach for monitoring the activity of the weak/old people from a distance. After the training process, ML classifies the action based on input accelerations.
Various types of devices have been used in HAR [22]. In [23], an automatic detection of physical activity (PA) system consisted of five accelerometers and a heart rate monitor based on the Polar chest strap (Wearlink). Another heavy recording device [24] included a chest analog accelerometer device, and wrist accelerations of ADXL202 were used to collect the motion data. Both of these approaches have a decent capacity to achieve real-time data, but multiple sensors can cause additional burdens to users. Other HAR applications employ devices that are embedded in various sensors and have lightweight, portable characteristics. Smartwatches with embedded accelerometers can be used for activity recognition systems that collect data [25,26]. Sensor readings from mobile sensors are also useful for human activity classification [27]. Since these devices are not fixed with to the body's center, e.g., the chest, it is more challenging to acquire distinctive data between multiple activities.
LG is easy to implement and train efficiently, but it is less effective with non-linear problems because it has a linear decision surface. LDA is also a fast algorithm that uses the mean values of the classes and maximizes the distance between them. However, if the distribution's mean values are shared between the classes, LDA cannot find a new linearly separable axis. KNN can plug in any distance metric to work with complex objects, but it is a distance-based approach, so the model can be badly affected by outliers, leading to overfitting.
CART is good for interpretation and visual presentation. With automatic feature selection, unimportant features do not impact the result. Nevertheless, it is susceptible and has high variance. A small change in the data can influence the prediction considerably. NB needs less training data to perform better than LR. It assumes that all the features are independent; meanwhile, the features can relate to each other in many practical cases. SVMs work well with a clear margin of separation by using a subset of training points in the decision function (support vectors), which is memory efficient. They have issues with large datasets due to their time-consuming nature, causing reduced prediction quality when there much noise in the data.
RF is one of the most conceivable algorithms to be implemented into the ML model. Each decision tree generates its prediction by comparing the features of the acquired value with the data of trained nodes. Each node separates the input data into a more specific range. After multiple comparisons, the decision tree provides a prediction. The same progress occurs with other trees. Eventually, the last result comes from the average prediction of all decision trees in the forest. This technique can avoid variation and solve unexpected noise well because each decision tree can act as an analyst [28].
The IoT [29] currently has usage cases in primary healthcare for controlling and managing dire situations during unsecured health circumstances such as coronavirus quarantine [30]. MQTT is an outcome and assessment information set (OASIS) standard messaging protocol for the IoT, which has been used widely in the medical monitoring system, as discussed in [31]. In [32], the authors addressed the design MQTT protocol for temperature control in a warehouse using ESP8266 and Wi-Fi. The obtained data were shared to the Baidu intelligent cloud server using MQTT.
In this project, the first model contained all the data, but with only two general classification types. Two following models included the minimized training number with specific classification categories. The final result depends on the logic execution, flowing from the first model to the others instead of majority voting decision. In this way, all models can have supervised learning with ML algorithms without neural network support thanks to the logic flow between models with specific training ranges. In addition, all ML algorithm validation was performed in each model to determine the most suitable one for each ML model. In this application, RF brings the highest score to all, but the results could be different in other applications. Practically, PTLE allows multiple ML algorithms in its system that increase ML flexibility. Furthermore, the logical flow between the trained models leads to high accuracy in the final prediction. This research utilized a M5stickC wearable device, which consists of a microelectromechanical system (MEMS) three-axis accelerometer [33]. The proposed design used the MQTT protocol for ESP32 [34] and a PC for messaging transfer between the wearable device-cloud-ML system, as demonstrated in Figure 1.
The IoT [29] currently has usage cases in primary healthcare for controlling and managing dire situations during unsecured health circumstances such as coronavirus quarantine [30]. MQTT is an outcome and assessment information set (OASIS) standard messaging protocol for the IoT, which has been used widely in the medical monitoring system, as discussed in [31]. In [32], the authors addressed the design MQTT protocol for temperature control in a warehouse using ESP8266 and Wi-Fi. The obtained data were shared to the Baidu intelligent cloud server using MQTT.
In this project, the first model contained all the data, but with only two general classification types. Two following models included the minimized training number with specific classification categories. The final result depends on the logic execution, flowing from the first model to the others instead of majority voting decision. In this way, all models can have supervised learning with ML algorithms without neural network support thanks to the logic flow between models with specific training ranges. In addition, all ML algorithm validation was performed in each model to determine the most suitable one for each ML model. In this application, RF brings the highest score to all, but the results could be different in other applications. Practically, PTLE allows multiple ML algorithms in its system that increase ML flexibility. Furthermore, the logical flow between the trained models leads to high accuracy in the final prediction. This research utilized a M5stickC wearable device, which consists of a microelectromechanical system (MEMS) three-axis accelerometer [33]. The proposed design used the MQTT protocol for ESP32 [34] and a PC for messaging transfer between the wearable device-cloud-ML system, as demonstrated in .

Data Acquisition
The wearable device M5-StickC [35] was equipped on the chest to acquire acceleration data from 5 people. The utilized sensor was a triple-axis MEMS accelerometer in MPU6886. A digital output X-, Y-, and Z-axis accelerometer with programmable full-scale range of ±2 g, ±4 g, ±8 g and ±16 g and integrated 16-bit analog-to-digital Converter was used. For practical purposes in real-time, the data frequency was about 10 Hz because higher

Data Acquisition
The wearable device M5-StickC [35] was equipped on the chest to acquire acceleration data from 5 people. The utilized sensor was a triple-axis MEMS accelerometer in MPU6886. A digital output X-, Y-, and Z-axis accelerometer with programmable full-scale range of ±2 g, ±4 g, ±8 g and ±16 g and integrated 16-bit analog-to-digital Converter was used. For practical purposes in real-time, the data frequency was about 10 Hz because higher frequencies consume more battery energy, requiring more frequent device charging. The X-axis, Y-axis, Z-axes of the accelerometer device are represented in .

Input Features
The accelerometer data were acquired and saved to the text file for training. The provided data from the accelerometer were Xacc, Yacc, and Zacc, which are the acceleration of the X-axis, Y-axis, and Z-axis, respectively. From these data, other features were calculated before being used in ML models. Totally, there were 9 features in operation, as described below: [Xacc, Yacc, Zacc, ΔXacc, ΔYacc, ΔZacc, Δacc_Norm, Δ Roll, Δ Pitch] as shown in Table 1, where:

Regular ML Model for Classification
In the traditional method, the ML model trains all types of activities in one model. Five behavior categories were fed into the ML model for the training and validation process. Once the model was ready, it was capable of predicting the acceleration inputs, as illustrated in . This technique's accuracy can meet the considerable challenge when the sensor data contain significant noise and random jumping values as spikes.

Input Features
The accelerometer data were acquired and saved to the text file for training. The provided data from the accelerometer were Xacc, Yacc, and Zacc, which are the acceleration of the X-axis, Y-axis, and Z-axis, respectively. From these data, other features were calculated before being used in ML models. Totally, there were 9 features in operation, as described below: [Xacc, Yacc, Zacc, ∆Xacc, ∆Yacc, ∆Zacc, ∆acc_Norm, ∆ Roll, ∆ Pitch] as shown in Table 1, where: ∆acc_Norm = ∆Xacc 2 + ∆Yacc 2 + ∆Zacc 2 Table 1. ML inputs and output.

Regular ML Model for Classification
In the traditional method, the ML model trains all types of activities in one model. Five behavior categories were fed into the ML model for the training and validation process. Once the model was ready, it was capable of predicting the acceleration inputs, as illustrated in Figure 3. This technique's accuracy can meet the considerable challenge when the sensor data contain significant noise and random jumping values as spikes.

System Overview
As shown in , the total system contained 2 main stages. The first stage was about the training model by ML algorithms with accelerations. In the second stage, all models were well-trained and converted the real-time acceleration into the corresponding activity based on the logical execution.

System Overview
As shown in , the total system contained 2 main stages. The first stage was about the training model by ML algorithms with accelerations. In the second stage, all models were well-trained and converted the real-time acceleration into the corresponding activity based on the logical execution.

Parallel Training Models
In this case, the PTLE system contained 3 ML models under training in parallel as shown in . The first model included all data labeled as 'normal' and 'abnormal' activities. The second model only trained the 'sit', 'walk' and 'sleep' types. The third model trained with 'cough' and 'fall' data.

Parallel Training Models
In this case, the PTLE system contained 3 ML models under training in parallel as shown in Figure 5. The first model included all data labeled as 'normal' and 'abnormal' activities. The second model only trained the 'sit', 'walk' and 'sleep' types. The third model trained with 'cough' and 'fall' data.  With this kind of task division, each model will focus more on the specific categories instead of working on all activities simultaneously. The cough is essential to detect, so when the user coughs during walking, sitting, or sleeping, the data are still in the cough category.

Parallel Training Models
After the training process, three models were put to work following the propagation of logical execution. The mission of the first model was to separate abnormal symptoms from normal activities. Once the abnormal class was detected, the PTLE system passed the data into the third model, which distinguished between cough and fall. In another case, the data come to the second model, and sit, walk, or sleep was recognized therein, as described in . With this kind of task division, each model will focus more on the specific categories instead of working on all activities simultaneously. The cough is essential to detect, so when the user coughs during walking, sitting, or sleeping, the data are still in the cough category.

Parallel Training Models
After the training process, three models were put to work following the propagation of logical execution. The mission of the first model was to separate abnormal symptoms from normal activities. Once the abnormal class was detected, the PTLE system passed the data into the third model, which distinguished between cough and fall. In another case, the data come to the second model, and sit, walk, or sleep was recognized therein, as described in Figure 6.
when the user coughs during walking, sitting, or sleeping, the data are still in the cough category.

Parallel Training Models
After the training process, three models were put to work following the propagation of logical execution. The mission of the first model was to separate abnormal symptoms from normal activities. Once the abnormal class was detected, the PTLE system passed the data into the third model, which distinguished between cough and fall. In another case, the data come to the second model, and sit, walk, or sleep was recognized therein, as described in . Figure 6. Logical execution chart of the PTLE system. Figure 6. Logical execution chart of the PTLE system.

Suitable Algorithm Selection
At this stage, the most fitting algorithm has to be selected. The function K-fold and cross-validation were utilized to evaluate the ML algorithms. Cross-validation is a resampling procedure used to evaluate machine learning models on a limited data sample.
The procedure contains a single parameter called K, which refers to the number of groups into which a given data sample will be split. This approach involves randomly dividing the set of observations into K groups, or folds, of approximately equal size. The first fold is treated as a validation set, and the method fits the remaining K − 1 folds. In this case, 10 K-folds were used in cross-validation-the score was in the range of 0 to 1. The ML model had a higher score and achieved better accuracy.
As described in Section 2, seven popular algorithms of ML classification were compared with each other to determine the most suitable algorithm for this particular circumstance. Table 2 reports the mean score and standard deviation (Std) score of 10-fold validation for model 1 (normal-abnormal). As a result, the RF obtained the best score with less variation than the other algorithms, so this algorithm was chosen as the primary ML model for the activity classification. The RF hypermeters constitute 100 trees in the forest; 1 leaf minimum sample is needed to be at a leaf node, and 2 minimum sample splits are required to split an internal node. Nodes were expanded until all leaves contained less than the minimum sample splits.
RF changes the algorithm in terms of how the sub-trees are learned so that the resulting predictions from all subtrees have less correlation using the bootstrap method, as demonstrated in Figure 7. In each bootstrap training set, about one-third of the instances enter each decision tree [36]. RF is an ensemble of decision trees that includes 3 main features for data processing: • Every single tree is constructed of a different sample of rows. At each node, a different sample of features is selected for splitting to the following stages.

•
Each of the trees provides its prediction. • These predictions are averaged to supply the last decision value based in the tree outputs.  As shown in , RF worked well with all 3 models in PTLE system. As reported above, model 1 surpassed the other algorithms with the highest accuracy after 10-fold validation. In models 2 and 3, RF still achieved the most impressive results with high mean and less Std, even though CART and KNN were also good candidates. Therefore, the RF was selected as the utilized algorithm for all 3 models to classify the activities.  As shown in Figure 8, RF worked well with all 3 models in PTLE system. As reported above, model 1 surpassed the other algorithms with the highest accuracy after 10-fold validation. In models 2 and 3, RF still achieved the most impressive results with high mean and less Std, even though CART and KNN were also good candidates. Therefore, the RF was selected as the utilized algorithm for all 3 models to classify the activities. As shown in , RF worked well with all 3 models in PTLE system. As reported above, model 1 surpassed the other algorithms with the highest accuracy after 10-fold validation. In models 2 and 3, RF still achieved the most impressive results with high mean and less Std, even though CART and KNN were also good candidates. Therefore, the RF was selected as the utilized algorithm for all 3 models to classify the activities.

Performance Validation
To validate the proposed technique, the following ML factors were calculated: precision, recall, and F1-Score based on true positive (TP A ), false positive (FP A ), and false negative (FN A ) of class A.
• TP A is the number of predictions where the classifier correctly predicts class a. • FP A is the number of objects that do not belong to class a but are predicted as class a. • FN A is the number of objects from class A predicted to another class. • F1-Score provides a single score that balances the concerns of precision and recall in one number. F-Score delivers a way to combine both precision and recall into a single measure that captures both properties. Once precision and recall have been calculated for the multiclass classification problem, the two scores can be combined into the calculation of the F-Measure. As with precision and recall, a poor F-Measure score is 0.0, and a best or perfect F-Measure score is 1.0 • Accuracy is the fraction between number of correct predictions and number of predictions.
For training and testing process, the user wore the device on their chest, which sent the accelerations to the PC via Wi-Fi. Table 3 demonstrates the validation result of the PTLE method on the testing sample, which is about 30% of the total collected samples; the rest of the samples were used to train the model. The system showed a balance of prediction with a good F1-Score and overall accuracy of 99%.

Real-time Test Validation
In the experiment, two different users equipped the M5-StickC on their chests; one was an old person, and another had just recovered from the flu. These users performed activities following the indication during a specific period. The fall events were acquired with the support of a volunteer group.
The M5stickC is a development platform that includes flash memory of 4 MB and a Lipo-battery of 95 mA-3.7 V, which the Arduino Software (IDE) [38] can program. This board contains the MEMS 3-axis accelerometer MPU6886. The acceleration range is ±2 g in this application.
ML models were designed in Python based on scikit-learn [39], a powerful and easyto-use free, open-source Python library for ML development and evaluation. The models were operated by a PC processor: Intel(R) Core (TM) i7-10850H CPU @ 2.70 GHz.
This wearable device acquired the sensor data, which were sent to the ML model on PC via Wi-Fi based on MQTT protocol via Ubidots software [40] which performs functions such as IoT data analysis and visualization. The ML models received these data and performed the activity prediction. Each action was carried out for a period and the predictions were verified in real-time, with the ground truth being the current activity.
Here, the regular ML mode with the RF algorithm was designed, where a single model was trained to classify all five activities. The comparison between the two methods was demonstrated to analyze the efficiency of each approach. There were numerous numbers of samples acquired for ML model validation, as reported in Table 4. The regular model had significant difficulty in making the prediction for sleep. The accelerometer frame collected data in terms of the X-Y-Z axis during activities such as lying on the bed and other activities that can cause confusion for the regular ML model. Meanwhile, the PTLE technique was still able to classify sleep well, with high precision and good recall. Regarding sit and walk, the regular model could achieve better prediction than sleep, with F1 scores being acceptable, but it was still inferior to the proposed system. The PTLE system showed that the prediction balance with precision and recall were always higher than 0.80.
Cough and fall are the two most crucial categories to detect. The regular model prediction was average at this point. Low precision in cough means that the model misunderstands other behaviors such as cough. In contrast, this ML model improperly predicted many fall cases as other behaviors brought uncertainty to the results. With more specific training, the PTLE system could accomplishes stable prediction with high efficiency. Although fall recall is still not uppermost, the fall prediction is already optimized significantly with absolute precision and a high F1 score. The PTLE system had a good performance in previous tests during the training process. Obviously, there was slight difference in the results between the two tests because the data were obtained from different users at different periods. Figures 9 and 10 illustrate the correct number of prediction samples from both methods in each activity. In normal activities, PTLE method provided more than 10% of precise decisions compared with the regular method, which indicates the superior operation based on the logical execution after the parallel training for the models.

Bar Chart Comparision of Correct Prediction Number
Sensors 2023, 23, x FOR PEER REVIEW 12 of 16 significantly with absolute precision and a high F1 score. The PTLE system had a good performance in previous tests during the training process. Obviously, there was slight difference in the results between the two tests because the data were obtained from different users at different periods.

Bar Chart Comparision of Correct Prediction Number
illustrate the correct number of prediction samples from both methods in each activity. In normal activities, PTLE method provided more than 10% of precise decisions compared with the regular method, which indicates the superior operation based on the logical execution after the parallel training for the models. Regarding abnormal activity detection, cough was recognized very well by the PTLE system. Its correct prediction was almost absolute, which is a huge advantage since this symptom is important to realize for weak people. The fall recognition was also reliable, with approximately 98% of proper outputs. Thus, the PTLE method is satisfactory for tracking abnormal behaviors of weak people in real-time.  Table 5 reports the standard deviation (Std) and the prediction accuracy of the correct prediction from the two models. In normal activities, the Std of PTLE was less than the regular model and vice-versa in the abnormal case. Regarding the accuracy, the PTLE accomplished a superior number of correct predictions in both situations.  Regarding abnormal activity detection, cough was recognized very well by the PTLE system. Its correct prediction was almost absolute, which is a huge advantage since this symptom is important to realize for weak people. The fall recognition was also reliable, with approximately 98% of proper outputs. Thus, the PTLE method is satisfactory for tracking abnormal behaviors of weak people in real-time. Table 5 reports the standard deviation (Std) and the prediction accuracy of the correct prediction from the two models. In normal activities, the Std of PTLE was less than the regular model and vice-versa in the abnormal case. Regarding the accuracy, the PTLE accomplished a superior number of correct predictions in both situations.

Activity Visulization on IoT Dashboard
The activity prediction were sent to the Ubidots dashboard with two logic values: 0-No (no colour); 1-Yes (red colour) as shown in Figure 11. In this example, the user coughed, so the cough box assumed a red colour with a logic of 1 and the other action box had no colour. During sit, walk, or sleep, if the user coughed, the ML system would predict cough over the others. Number of coughs per day can be calculated and observed in the website history. Regarding the fall events, once they occur, they will remain as logic 1 with a red color as an alarm to the observers until the user presses the restart button on the wearable device or there is a manual intervention from the responsible website/PC control. During this fall event, the other activities are still under normal prediction of the ML system. Additionally, the observers can understand the health state and the emergency level of the user.

Conclusions
The paper described a new system classification based on ML models to optimize the prediction quality for the risk factors of health behavior for weak people. The PTLE system managed the trained models following logical operation, which reduced the complexity of each ML model and upgraded the output accuracy. In addition, the proposed idea enables a new approach of multiple-algorithm combination per ML structure in one training flow. Moreover, the project utilized a low-cost and small-size device conveniently equipped with to body for supervising vital activities, cough and fall, from other normal actions. An IoT protocol was implemented to support communication between the sensor and workstation with the MQTT and cloud that help the responsible Number of coughs per day can be calculated and observed in the website history. Regarding the fall events, once they occur, they will remain as logic 1 with a red color as an alarm to the observers until the user presses the restart button on the wearable device or there is a manual intervention from the responsible website/PC control. During this fall event, the other activities are still under normal prediction of the ML system. Additionally, the observers can understand the health state and the emergency level of the user.

Conclusions
The paper described a new system classification based on ML models to optimize the prediction quality for the risk factors of health behavior for weak people. The PTLE system managed the trained models following logical operation, which reduced the complexity of each ML model and upgraded the output accuracy. In addition, the proposed idea enables a new approach of multiple-algorithm combination per ML structure in one training flow. Moreover, the project utilized a low-cost and small-size device conveniently equipped with to body for supervising vital activities, cough and fall, from other normal actions. An IoT protocol was implemented to support communication between the sensor and workstation with the MQTT and cloud that help the responsible people monitor the vulnerable person at a distance.
In the future, the designed system will be tested with more people to learn more about the pros and cons of the system. Obtained measurements from various people can support the project in developing the device in terms of prediction precision and signal communication, which are extremely useful not only in the case of medical care but also in HAR generally.