Keywords

1 Introduction

A person’s basic need is his well-being. It represents a person’s overall health, including his or her body, mind, and social status. With aging, a person’s well-being deteriorates, necessitating continuous monitoring of key markers. Because the current healthcare system is unable to provide tailored care for each individual, machines must be introduced to take the place of caregivers in order to respond to emergencies quickly. Furthermore, there is a significant disparity between rural and urban areas in terms of effective healthcare and personal health monitoring. The Internet of things (IoT) is a lifesaver for people who cannot go to well-established hospitals for continuous health monitoring. On the other side, there is a scarcity of experienced clinicians who can effectively manage emergencies. By transmitting health parameters of patients through accurate sensors and strong servers, IoT can connect people in rural areas with such clinicians. Clinicians might be notified about their patients’ health status. The process of providing agile healthcare is improved when IoT-based health parameters are further examined and classified into healthy and anomalous classifications using appropriate machine learning models. IoT-based health monitoring systems have been increasingly popular in recent years [1,2,3,4]. IoT-enabled sensors were used to construct a heart attack early warning system [1]. An alarm system was implemented to notify caregivers and clinicians about a patient’s heart health. A threshold was also set to alert the patient to any changes in his or her health. A health monitoring system based on the Internet of things and Raspberry Pi boards was launched [2] to capture vital health parameters and update them on the hospital’s Website for personalized monitoring of each patient by clinicians, who were informed on anomalies. Data storage for future reference, on the other hand, was not made easy. To determine whether a person had drank alcohol or not, basic health measures such as pulse rate, blood pressure, and temperature were examined [3]. Several sensors were linked to the hardware board, with sensor interfaces allowing data to be easily transmitted to a remote controlled clinical analysis center for enhanced monitoring in the event of an emergency. One disadvantage is that there is no provision for storing data. Machine learning has been widely utilized in healthcare to predict disease [4]. On the Genuino board [4], a live health parameter monitoring system was established for screening patients based on five vital health factors. The patients’ heart conditions were monitored using a wearable ECG sensor. For online patient monitoring, a support vector machine (SVM) model was trained on sensor information to respond to anomalies.

A robust microcontroller prototype with multiple sensors intended to assess the patient’s vital parameters such as pulse rate and temperature is included in the proposed machine learning and IoT-based health monitoring system. With the growing demand for remote patient monitoring, a low-cost health monitoring system is the answer to the patients’ problems. The application of a machine learning model, enhanced with IoT facilitation, for remote data collecting and real-time anomaly detection of important health metrics is proposed in this study. The health parameters that are measured are transferred to the cloud for storage. This makes data retrieval and action easier in future. A Wi-Fi module on the Arduino microcontroller delivers data from the private cloud server. On a secure portal, a Website was created to display the patient’s health data. The findings of this study’s trial phase appeared promising; therefore, the system was expanded to a real-time operation to assist patients and clinicians in finding a flexible health monitoring system for low-cost personal healthcare.

The principal contributions of this research work are as follows:

  • Dependable, low-cost, low-power IoT-based health monitoring system that can track physiological parameters.

  • Accurate machine learning-based real-time anomaly pattern detection in patients, which can be utilized to monitor crucial data on a regular basis.

2 Methodology

2.1 Data Acquisition

This study proposes IoT-based healthcare using an ESP8266 board. The project uses a pulse sensor to monitor the patient’s pulse rate and an LM-35 temperature sensor to measure the patient’s temperature. The patient’s pulse and temperature were monitored and transferred to a Web server. The suggested Internet of things-based healthcare system might be used as a remote tool for clinicians to monitor patient health from remote place.

2.2 Experimental Setup

A pulse sensor, LM 35 temperature sensor, ESP-8266, a voltage regulator IC, an IoT server, and a logistic regression machine learning model are included in the proposed machine learning and IoT-based health monitor system. Figure 1 depicts the proposed system’s overall flow diagram.

Fig. 1
figure 1

Block diagram of machine learning and IoT-based health monitor system

2.2.1 Pulse Sensor

A pulse sensor monitors change in the blood vessel’s volume. When attached to an Arduino board, a sensor that can detect heart rate is required. Pulse sensor is an Arduino-compatible heart rate sensor with a well-designed plug-and-play interface.

2.2.2 LM35 Temperature Sensor

The LM35 temperature sensor was employed in this study. This sensor’s output is an analog signal proportional to the temperature in Celsius. There was no need for calibrating. The temperature sensor has a sensitivity of 10 millivolts per degree Celsius, and the output voltage rises as the temperature rises.

2.2.3 ESP8266—Wi-Fi Module

The ESP8266 chip is incorporated in the microcontroller unit-ESP8266 board’s ESP12E module. It includes networking capabilities as well as a serial port. The ESP8266 chip also includes a 32-bit LX106 RISC microprocessor. It works with the real-time operating system and has a clock frequency that may be adjusted. The memory space on the microcontroller unit is sufficient to hold real-time medical data. It operates at a very high speed and is equipped with a Wi-Fi module, making it perfect for IoT applications. The ESP8266 is a standalone board that includes all of the modules required for IoT applications. To read digital inputs, the ESP8266 has enough digital input and output pins. The drain is represented by zero volts, whereas the source is represented by a maximum voltage. The ESP8266 features seventeen general-purpose input–output pins for interacting with flash memory, as well as a universal asynchronous receiver-transmitter connector for serial data reception and transmission.

3 Proposed System

3.1 Working of the Proposed Machine Learning and IoT-Based Healthcare System

The proposed IoT-based health monitor system has a simple operation. The circuit is supplied power at first. This power source is either a computer or a battery. A USB cable was used to link the computer to the ESP8266 to acquire electricity. After connecting the ESP8266 boards to the PC, the LEDs on the boards began to blink. The pulse sensor was spotted blinking green light, indicating that the ESP8266 is ready to detect heartbeat. Because heartbeats are continuous, the other two pins are dedicated to ground and power. The temperature sensor utilized in this study, the LM35, has three pins. The health record was stored in the database after the pulse and temperature were sensed. The information is also presented on the liquid crystal display.

When powered by an external source, the ESP8266 board captures the pulse rate information from the pulse sensor and the patient’s temperature from the LM35 sensor. The pulse sensor uses an LED and a phototransistor to measure the pulse on the fingertip. The phototransistor detects the infrared flashes on the light emitting diode, and its resistance fluctuates with the detected pulses. The pulse rate, which is proportionate to the patient’s heartbeat, is detected via a two-millisecond interrupt, and the ESP8266 board captures the sensor’s equivalent output value, which is then digitized. Every minute, the pulse rate is also recorded.

As shown in Eq. (3.1), the digital output is calculated from the recorded output (3.2). VCC, the energizing voltage, is set to 5 V.

$$V_{\text{o}} = (V_{{\text{CC}}} /1024)*{\text{recorded output}}$$
(3.1)
$${\text{Temperature}} = (V_{{\text{CC}}} /1024)*{\text{recorded output}}*100$$
(3.2)

As a result, the temperature of the patient was recorded by looking at the temperature sensor’s analog output. The captured data were sent to the server using the ESP8266 Wi-Fi module, which enabled IoT. It was also shown on the liquid crystal display. A digital dashboard was used in conjunction with an Adafruit IoT server. It allows real-time data to be logged, displayed, and interconnected. It is advantageous to send data to a remote user. It can also connect to other Internet-connected gadgets.

3.2 Machine Learning-Based Anomaly Detection

The ESP8266 module’s real-time temperature and pulse rate data were utilized to train three machine learning algorithms to detect irregularities in the patient’s health. As classification models, such as the K-nearest neighbor model, the logistic regression model, and the support vector machine [5], were employed. They are statistical models for analyzing a feature set with independent factors in order to predict the output label. On evaluation, the algorithm that best matches the dependent and independent variables is selected as the best model. Based on the threshold value, the predicted probability is translated into a class label. These statistical models can be used to classify binary and multi-class data.

3.2.1 Pre-processing the Dataset

The detection and correction of unnecessary data values in a dataset are part of dataset pre-processing. Average values are used to replace such data values. Similarly, using appropriate data augmentation techniques, the empty data values are filled.

3.2.2 Model Creation

The effective characteristics that were narrowed down after pre-processing the data were used to fit the statistical model on 60% of the training data [6]. The dataset was separated into two feature sets, one for training and one for testing, to ensure that the projected outcome remained consistent. To enumerate the inaccuracy between the projected output labels and the genuine output labels, a cost function is generated. It calculates the amount of variance between the true and anticipated values. Model loss is the result of the cost function’s value. The Eqs. (3.3) and (3.4) define the cost function \(J(\theta )\), and the hypothesis function is \(h_\theta\) [7]. The cost function is used to calculate the difference between the predicted and actual value.

$$J\left( \theta \right) = \frac{1}{m}\mathop \sum \limits_{i = 1}^m \cos t(h_\theta \left( {x^{\left( i \right)} ,y^{\left( i \right)} } \right)$$
(3.3)
$$\cos t(h_\theta \left( {x^{\left( i \right)} ,y^{\left( i \right)} } \right) = \left\{ {\begin{array}{*{20}c} { - \log \left( {h_\theta \left( x \right)} \right)} & {{\text{if}}\,y = 1} \\ { - \log (\left( {1 - h_\theta \left( x \right)} \right) } & {{\text{if}}\,y = 0} \\ \end{array} } \right.$$
(3.4)

A negative function is introduced to increase the likelihood of lowering the model’s cost function or loss. Reducing model loss would boost the chances of making the correct prediction.

3.2.3 Validation and Testing Phase of the Model

The validation set contains 20% of the data, which is used to cross-validate the model for hyperparameter tweaking, while the test set contains the remaining 20%. The test data are used to assess the model’s overall performance.

4 Results and Discussion

To detect anomalies in the patients’ health conditions, the KNN, logistic regression, and SVM models were created, trained, and tested on real-time temperature records and pulse rate readings. The confusion matrices of three statistical models used to forecast anomalous health conditions are shown in Fig. 2.

Fig. 2
figure 2

Confusion matrices of a logistic regression, b KNN, and c SVM

The performance evaluation of statistical models reveals that KNN is the best model for real-time anomaly identification in patients’ health conditions, with 100% efficacy. Table 1 lists the models’ precision, recall, and F1-score, while Table 2 lists the other assessment parameters such as the Hamming loss, zero–one loss, and Cohen’s kappa coefficient. The k-NN yields the best results of cent percent accuracy, precision, recall and F1-score as displayed in Table 2 and reduced loss as shown in Table 3.

Table 1 Evaluation of statistical models
Table 2 Performance metrics of the statistical models

A comparative study on the models in the existing literature is presented in Table 3.

Table 3 Performance comparison

As a result, the k-NN model achieves 100% accuracy in detecting anomalous health conditions and outperforms other models [1118] in the literature for IoT applications. As a result, the suggested IoT health monitoring system with KNN classifier qualifies as a precise remote medical help for clinicians. Furthermore, the binary classifier has a high precision, recall, and F1-score in recognizing abnormal health conditions in patients.

5 Conclusions and Future Work

This study proposes a machine learning and Internet of things-based health monitoring system. Clinicians can monitor the vital parameters of patients on a regular basis with this remote healthcare system. Remote examination of crucial health metrics is made possible by an IoT-enabled monitoring system. As a result, the Internet of things improves the healthcare system for patients by giving them more control over remote monitoring. Furthermore, the introduction of a machine learning model with 100% accuracy aids in real-time health anomaly identification, allowing for speedy diagnosis of health issues in emergency situations. As a result, the proposed system could serve as an accurate, reliable, and practical technology for providing quick medical assistance.

The security of healthcare data will be reviewed in future. An alarm mechanism could be added to the gadget to notify relevant medical personnel if the patient’s pulse rate and temperature are abnormal.