IoT-based automated system for water-related disease prediction Authors: Bhushankumar Nemade, Kiran Kishor Maharana, Vikram Kulkarni, Surajit mondal, G S Pradeep Ghantasala, Amal Al-Rasheed, Masresha Getahun, Ben Othman Soufiene Published: 2024 ABSTRACT AbstractHaving access to potable water is a fundamental right to well-being. Despite this, 3.4 million people die from diseases caused by water each year, and 1.1 billion people lack access to potable drinking water. Although industrialization, durable infrastructure, and rapid development have increased living standards, the water problem has left humanity defenseless. As different human activities have contaminated these water reserves, according to an estimate, water is the cause of 80% of ailments. As a result, it is necessary to permit enough infrastructure to ensure the security of a reliable supply of potable water. Thus, a real-time WBPCB dataset with 17 features and a proposed IoT-based system to collect data are used in this research to address the issue. The research paper provides a system for predicting diseases and forecasting long-term trends. Classification is performed using Random Forest, XGBoost, and AdaBoost, which have accuracy rates of 99.66%, 99.52%, and 99.64%, respectively. Forecasting is performed using LSTM, which has an MSE value for the pH parameter of 0.1631. The paper introduces TS-SMOTE, a novel hybridized time-series SMOTE data augmentation approach. Additionally, it offers an IoT system that uses H-ANFIS to gather data in real-time and identify attacks.Keywords: Water-borne diseases prediction, Water quality prediction, IoT-based diseases prediction, Time-series data, Forecasting diseases, TS-SMOTE, Time-series data augmentation, H-ANFIS, Long short-term memory, LSTMSubject terms: Energy science and technology, Engineering Introduction Human life and public health depend on water. However, access to safe drinking water is not available to most people. It has evolved into a worldwide issue that is thought to impact 40% of the world’s population altogether1. In addition, it is anticipated that 3 billion people would not have access to fresh water by 2025, forcing them to live in a water-stressed environment2. This will lead to an increase in water-related illnesses and fatalities in both developed and developing nations. While the majority of instances are recorded in developing nations, wealthier nations also suffer from this3–5. Drinking water that has been tainted by human or animal waste that contains harmful microorganisms is the main cause of waterborne illnesses. With 1.8 million fatalities and 4 billion episodes of sickness yearly, watery diarrhea is the most common infection that causes death and morbidity globally6. Drinking water is the primary source of waterborne illness transmission when an animal or human waste containing harmful microorganisms is involved. According to statistics, waterborne infections are the primary cause of death worldwide, accounting for close to 3.4 million fatalities per year and almost 4 billion episodes of sickness7. An estimated 73 million working days are expected to be lost annually owing to waterborne sickness, and an estimated 37.7 million Indians are thought to suffer from waterborne illnesses each year8,9. Moreover, it’s estimated that 1.5 million children die every year from diarrhea alone. Waterborne infections have a significant impact on a country’s healthcare costs and economic growth. Due to inadequate water supply management, particularly about drinking water and sanitation, many illnesses return every year during the warm and wet seasons10,11. Waterborne illnesses proliferate in areas of urban slums with weak urban management, rapidly growing economies, very dense populations, and subpar housing and sanitation12. At least 30% of all illness in Mumbai’s slum regions is attributed to water-related diseases, according to one research. In rural areas, the sewage and water systems are insufficient13. Water pollution in the communities is mostly caused by infiltration, leaching, and surface runoff from fields, a lack of sewage disposal facilities, and structural leakages. Waterborne infections are often brought on by a lack of knowledge, attitudes, and behaviors (KAB) about water management, sanitation, and defecation habits, according to studies conducted in rural India14. An all-encompassing strategy is needed to address water quality and waterborne illness, including increasing access to clean drinking water, strengthening water treatment and distribution infrastructure, and decreasing pollution from industrial and agricultural sources. While considering the patterns of human water usage, particularly in India. Due to the restricted fresh water supply, rural communities are forced to share their resources with the “privileged” urban population, resulting in a fictitious shortage for them throughout the summer. Making rural residents rely on untreated rivers, lakes, ponds, wells, and other sources15,16. The problem is evident and the convergence of IoT, machine learning, and time-series forecasting in water quality management can serve to solve this. Introduction of systems that are IoT powered built with advanced sensors for continuous data collection, automatically gathering information from water sources. Can help to develop real-time insights into critical metrics in water, such as pH, turbidity, temperature, or chemical contaminants. Continuous monitoring would be able to detect changes in water quality and limit the possibility that any contamination would make its way into the public. Machine learning algorithms, applied to these large real-time datasets, identify some of these faint patterns well enough to predict the outbreak of waterborne diseases by detecting an anomaly that traditional methods will have missed. Further, time-series forecasting built on such predictive capacity to estimate future trends of water quality based upon past history and can serve information on taking preventive action. It will be especially useful in taking all possible preventive measures against seasonal variation risks, be it due to industrial activities or sudden changes in the environment. Thus, the need of the hour asks for a relevant approach lie not only in real-time surveillance but also in risk prediction that enables much faster proactive responses. The management of water will then have a chance to make informed decisions that can lead to better health outcomes for the public, optimize resource use, and improve protection efforts of the environment in a scalable and efficient manner with the help of these technologies. Thus, this research helps to understand the root problem and presents preventive, detection and corrective measures. Figure 1. represents the Conceptual Framework of the research and its framework. Following sections represents the claims, scope and highlights of the research. Conceptual framework: interrelationship between individual module. Mapping of proposed system with research outcomes planned Develop an IoT-based system for improved data processing, cleaning, and visualization from diverse sources. Develop an IoT-based system for improved data processing, cleaning, and visualization from diverse sources. Water quality analysis. Water quality analysis. Implement machine learning (ML) techniques for testing, monitoring, and ensuring clean drinking water access in rural areas. Implement machine learning (ML) techniques for testing, monitoring, and ensuring clean drinking water access in rural areas. Long-term trend analysis. Long-term trend analysis. Novel time-series SMOTE technique. Novel time-series SMOTE technique. Improved public health infrastructure. Improved public health infrastructure. Propose IoT system, including sensors and data processing systems, with broader applications. Propose IoT system, including sensors and data processing systems, with broader applications. Create a database for ongoing research and analytical tool development. Create a database for ongoing research and analytical tool development. Web application development. Web application development. Scope of research Increase public awareness about the importance of drinking water quality and the connection to health, as well as the need for clean drinking water for domestic use. Increase public awareness about the importance of drinking water quality and the connection to health, as well as the need for clean drinking water for domestic use. Acknowledge surveillance and the importance of community response. Acknowledge surveillance and the importance of community response. Develop an IoT-based online monitoring system that uses sensors to collect necessary metrics, and apply tested algorithms to make real-time predictions of water quality. Develop an IoT-based online monitoring system that uses sensors to collect necessary metrics, and apply tested algorithms to make real-time predictions of water quality. Develop a real-time water quality monitoring system utilizing H-ANFIS for attack detection and MPCA for efficient data processing. Develop a real-time water quality monitoring system utilizing H-ANFIS for attack detection and MPCA for efficient data processing. Use pH, turbidity, temperature, and other parameter sensors, for parameter readings and an Arduino microcontroller to convey those readings Transceiver. Use pH, turbidity, temperature, and other parameter sensors, for parameter readings and an Arduino microcontroller to convey those readings Transceiver. Detect poor-quality water and alert the appropriate authorities before it is released for consumption, reducing the number of people who consume low-quality water and thereby reducing the severity of diseases such as diarrhea and typhoid. Detect poor-quality water and alert the appropriate authorities before it is released for consumption, reducing the number of people who consume low-quality water and thereby reducing the severity of diseases such as diarrhea and typhoid. Conduct investigations into outbreaks and intervention studies to assess available choices for interventions. Conduct investigations into outbreaks and intervention studies to assess available choices for interventions. Perform case-control or cohort studies to assess the contribution of water to illness risk. Perform case-control or cohort studies to assess the contribution of water to illness risk. Apply prescriptive analysis based on anticipated values to help decision-makers and policymakers. Apply prescriptive analysis based on anticipated values to help decision-makers and policymakers. The highlight of this research work is described below in Fig. 2: Overview of the research. To employ the techniques of Machine Learning (ML) and Deep Learning (DL) for predicting water-related diseases and mitigating potential risks at an early stage. To employ the techniques of Machine Learning (ML) and Deep Learning (DL) for predicting water-related diseases and mitigating potential risks at an early stage. To ensure real-time water quality testing, monitoring, and surveillance using an IoT-based system of water quality parameters of reservoirs used in rural households and public institutions. To ensure real-time water quality testing, monitoring, and surveillance using an IoT-based system of water quality parameters of reservoirs used in rural households and public institutions. To study long-term trends and forecast water parameters, using demographic and geographic data, and provide appropriate solutions. To study long-term trends and forecast water parameters, using demographic and geographic data, and provide appropriate solutions. To aid government agencies in guaranteeing proper water quality levels through ongoing monitoring, thereby lowering the frequency of diseases transmitted through the use of contaminated water. To aid government agencies in guaranteeing proper water quality levels through ongoing monitoring, thereby lowering the frequency of diseases transmitted through the use of contaminated water. To introduce TS-SMOTE – a novel Data Augmentation technique for time-series data. To introduce TS-SMOTE – a novel Data Augmentation technique for time-series data. Related work This review investigates state-of-the-art methods for predicting and avoiding waterborne diseases. To improve strategies for identifying and managing these diseases, researchers have used a variety of techniques, including machine learning and deep learning models. Whether through infectious disease forecasting models or innovative water quality forecasting systems, the studies provide insight on both achievements and challenges in the pursuit of precise and timely disease prevention. The significance of these advancements is based on their potential to transform public health approaches, allowing for more efficient and specific measures for addressing waterborne hazards. Hussain et al., presented machine learning methods to predict positive cases of waterborne infections. For the years 2017–2020, these researchers have collected typhoid and malaria patient records in order to create a machine learning-based model to detect waterborne infections. They trained and tested various ML models and found that Random Forest performed the best with 77% accuracy in the prediction of positive cases of waterborne diseases. The study also identified the most important input features for disease prediction. The system’s limitations include a lack of patient symptom information. The authors proposed additional research by utilizing social media surveys and hyperparameter approaches to increase the system’s accuracy17. The US Department of Health and Human Services developed a “Waterborne Disease Outbreak Investigation Toolkit”, which provides a comprehensive guide for investigating and controlling waterborne disease outbreaks. The toolkit covers a range of topics, including outbreak detection, sample collection, laboratory testing, case definition, data analysis, and control measures. The main advantage of this toolkit is that it provides step-by-step guidance and checklists for each stage of the investigation process, ensuring a thorough and systematic approach to outbreak investigation. However, the limitation of the toolkit is that it requires a significant number of resources and expertise and may not be accessible to all public health agencies or organizations. Overall, the toolkit is a valuable resource for public health professionals involved in investigating waterborne disease outbreaks18. Il Won Seo et al. presented the system to forecast water quality parameters using an ANN model with stratified sampling downstream of Cheongpyeong Dam. The study utilized eight water quality attributes from a dataset collected for the duration of three years, from July 2012–August 2015. The findings indicate that, except for turbidity, which has a R squared of just 0.638, the ANN ensemble model using stratified sample data performs well for seven parameters. Five parameters in RMSE have excellent performance below 1.0. However, in the case of turbidity, it results in R squared error of 0.683 and an RMSE of 10.01, which indicates that the ANN model is not able to predict rare events. The study concludes that further research is required to lessen the influence of rare events on the prediction of water quality parameters19. Wang M. et al. presented a deep learning-based technique for the multi-classification of infectious illnesses utilizing unstructured electronic medical records (EMR). This study used deep learning models that significantly improved the detection of infectious illnesses. The model was trained using hospital data from 20,620 occurrences of seven different types of disorders. The newly created Multiple Infectious Disease Diagnostic Model (MIDDM) by the researchers demonstrated a higher accuracy of 99.44% when compared to other models such as XGBoost, decision trees, Bayesian models, and logistic regression, which showed an accuracy of 96.19% and 90.13%, 85.19%, and 91.26%, respectively. The study aimed to aid medical professionals in the detection of infectious illnesses and the prevention of their social spread. The study had limitations since it looked just at one hospital and a small number of diseases, and it didn’t use the most precise diagnostic criteria20. Afaq Juna et al. presented a study of water quality assessment using KNN imputers and multilayer perceptron. The given study fills in the dataset’s missing values using a nine-layer multilayer perceptron (MLP) with a KNN imputer. It has seven different machine-learning algorithms. The recommended KNN imputer model has a 99.9% accuracy rate21. M. Wahyudi et al. presented research on the application of C4.5 and the Naive Bayes Algorithm to detect a potential increase in the case fatality rate for diarrhea. The research focused on a diarrhea epidemic from 2008 to 2014 and included data on 231 people. Algorithms such as C4.5 and Naive Bayes had accuracy rates of 82.82 and 79.85%, respectively. Its objective is to understand the factors that contributed to the pandemic, such as the population’s wealth, access to medical facilities and sanitization services, living arrangements, and family dynamics. The research addresses the problems of small sample sizes, the exclusion of classification models used to study diarrhea, and the neglect of optimum model-building parameters22. M. K. Verma et al. presented a research study aimed at developing an underwater monitoring and alert system for the prevention and control of water-borne diseases. This study provides a method for gathering data on the temperature, pH, turbidity, and oxidation of water sources in lakes, rivers, and seas dubbed an “underwater acoustic sensor network.” In this research, the underwater surface gateway has preprocessing and rule-based engine features that send an alarm to the nearby hospital. The underwater surface gateway sends data to government healthcare institutions through the internet, and similar data is used to perform analysis using big data for the control and prevention of water-borne illnesses23. S. Kurra et al. presented a study on water quality prediction using machine learning. The potability of the water is the subject of the study. PH, hardness, solids, chloramines, sulfate, conductivity, organic carbon, trihalomethanes, and turbidity are only a few of the nine properties of the dataset. These statistics were acquired from various locations around Andhra Pradesh. It uses the Decision Tree and KNN algorithms, with respective accuracy rates of 58.5 and 61.7%. The models performed badly because the dataset was deliberately created24. S. Rajmohan et al. presented the T-SMOTE algorithm, which focuses on the unique temporal-oriented oversampling technique known as T-SMOTE and takes into account the peculiarities of time-series datasets that are gradually and continually developing. T-SMOTE can handle both univariate and multivariate information, and it also excels at early prediction. The thorough tests on ten datasets show that T-SMOTE outperformed all of its cutting-edge rivals by a significant margin. Moreover, T-SMOTE has been implemented in several Microsoft Azure and Microsoft 365 situations, including the prediction of disc failure and excessive latency, and has significantly enhanced the performance of the online models25. S. Rajmohan et al. presented the T-SMOTE algorithm, which focuses on the unique temporal-oriented oversampling technique known as T-SMOTE and takes into account the peculiarities of time-series datasets that are gradually and continually developing. T-SMOTE can handle both univariate and multivariate information, and it also excels at early prediction. The thorough tests on ten datasets show that T-SMOTE outperformed all of its cutting-edge rivals by a significant margin. Moreover, T-SMOTE has been implemented in several Microsoft Azure and Microsoft 365 situations, including the prediction of disc failure and excessive latency, and has significantly enhanced the performance of the online models25. H. He et al. presented a study on “ADASYN: Adaptive Synthetic Sampling Approach for Imbalanced Learning”, For challenges involving the categorization of unbalanced data, the unique adaptive learning method ADASYN was introduced in this study. ADASYN was adaptively generated to lessen the bias caused by the unequal data distribution, artificial data samples for the minority class are created based on the original data distribution. Further, ADASYN automatically adjusted the classifier decision boundary to concentrate on those challenging classes samples, improving learning effectiveness. To achieve these two goals, dynamic weight adjustments and an adaptive learning method that takes distributions of data into account are both applied. Results from simulations on five data sets using various assessment measures were used to demonstrate the effectiveness of the technique26. Mushtaq Hussain et al. presented a study on “Machine learning based efficient prediction of positive cases of waterborne diseases”. Waterborne diseases have increased in Pakistan as a result of the increasing danger to water quality induced by fast population growth. A recent study at Ayub Medical Hospital from 2017 to 2020 used machine learning models to predict typhoid and malaria cases, with Random Forest demonstrating greater accuracy at 60% for malaria and 77% for typhoid. The study underlines the importance of input characteristics, highlighting age, history, and test findings as key factors in anticipating positive instances of waterborne illnesses. These findings suggest the possibility of developing tailored interventions and preventative measures based on these critical drivers, in addition to forecasting accuracy. The study highlights the value of data-driven approaches in public health by offering significant insights to inform actions to reduce the prevalence of waterborne infections in Pakistan17. N. Khant et al. presented a study that examined into “Impact of Climate Change on Waterborne Diseases: Directions towards Sustainability”. Climate change has a significant impact on the rise of waterborne diseases (WBDs), especially in developing countries such as those in the Association of Southeast Asian Nations (ASEAN). Vibrio cholerae, a common waterborne pathogen, is most common during severe weather changes. Cyclone Nargis in Myanmar (2008) and tropical cyclones in the Philippines highlight the urgency for ASEAN countries to implement policies addressing the impact of climate change on WBDs. The goals of this study are to (1) assess the health implications of climate change and identify necessary prevention policies, and (2) investigate the relationship between SDGs and climate change effects on WBDs for global sustainability. It is proposed that the SDGs be adapted for ASEAN countries in order to improve legislation on climate-related health issues. To address the multifaceted challenges posed by climate change on WBDs in ASEAN countries, effective collaboration among scientists, researchers, health professionals, and policymakers is critical27. Mithila et al. presented a study that investigates into the economic issues posed by water-borne illnesses as a result of climate change, with an emphasis on measures for reducing disease spread and providing access to safe drinking water. The research, that was conducted in Taltali upazila, Barguna district, with 384 respondents, had notable results. Approximately 41.4% have dysentery, 22.4% have increased treatment costs for water-borne infections owing to climate change, and 37.8% have difficulty accessing safe drinking water. Tube-well water is being used by 41.7% of the population, up from 19.3% five to ten years ago. Notably, 27.4% recognize the need for water filtering in disease prevention. According to the report, susceptibility to climate change is caused by variables such as rapid population expansion, resource disparity, food insecurity, remote water collection, insufficient medical facilities, poverty, and a weak health system. These findings highlight the complicated issues posed by water-borne infections in the face of climate change28. Singh et al. conducted a comprehensive study on “IoT-based greenhouse technologies for enhanced crop production: a comprehensive study of monitoring, control, and communication techniques”, emphasizing their potential to enhance crop production amidst varying climate conditions. The research highlights the significance of effective monitoring and control of environmental parameters, such as temperature, humidity, and soil moisture, crucial for optimal crop growth. They identify various communication techniques and sensors, offering insights into their advantages and limitations, which can guide farmers in selecting suitable technologies. The study also underscores the importance of addressing microclimate interactions within greenhouses and calls for further comparative analyses to optimize the implementation of smart greenhouse systems, thereby promoting sustainable agricultural practices29. Table 1 describes summary that presents studies on waterborne disease prediction and water quality forecasts using machine learning and deep learning models, highlighting potential limitations in data quality, sample size, and event prediction. Table 1The literature review summary.StudyMethodFindingsResultsConclusionResearch GapsLimitationHussain et al.Machine learning for predicting waterborne infections using patient recordsRandom Forest achieved 77% accuracy in detecting positive casesHighlighted factors contributing to waterborne infectionsEmphasized the need for improved data quality and patient contextLack of patient symptom information limits context for predictionsAbsence of patient symptom data reduces predictive powerUS Department of HealthDevelopment of a “Waterborne Disease Outbreak Investigation Toolkit”Provides a systematic approach to investigating outbreaksToolkit increased investigation efficiencySuggested the need for training and resources for effective implementationHigh resource and expertise requirements limit accessibility for smaller organizationsToolkit may be too complex for organizations with limited resourcesIl Won Seo et al.ANN model for forecasting water quality parametersPerformed well for seven parameters, struggled with turbidityAccurate predictions for six parametersAdvocated for enhancing predictive models with additional dataInability to predict rare events effectively and lack of consideration for real-time dataPoor turbidity prediction performance limits overall applicabilityWang M. et al.Deep learning for multi-classification of infectious illnesses using EMRMIDDM achieved 99.44% accuracy, outperforming other modelsDemonstrated high accuracy in disease classificationSuggested further testing on diverse datasets for generalizabilityLimited to one hospital and a small number of diseases restricts generalizabilitySmall dataset and lack of precise diagnostic criteria affect robustnessAfaq Juna et al.KNN imputers and multilayer perceptron for water quality assessmentKNN imputer model achieved 99.9% accuracyOutperformed other methods in accuracyIndicated the need for validation in real-world scenariosLimited exploration of other imputation methods and lack of robustness testingFocused primarily on imputation accuracy, lacking practical validationM. Wahyudi et al.C4.5 and Naive Bayes algorithms for diarrhea case fatality rate detectionAccuracy rates: C4.5 (82.82%), Naive Bayes (79.85%)Provided insights on critical case fatality ratesReinforced the importance of predictive modeling in health settingsSmall sample size and exclusion of other models limit findingsSmall sample size limits generalizability of resultsM. K. Verma et al.Underwater monitoring and alert system for water-borne diseasesData collection on temperature, pH, turbidity, and oxidationSuccessful in real-time monitoringSuggested further development for broader applicabilityNeed for real-time monitoring capabilities for proactive measuresDependence on sensor accuracy may affect data qualityS. Kurra et al.Machine learning for water quality predictionDecision Tree (58.5%) and KNN (61.7%) accuracy ratesLimited accuracy affected by dataset qualitySuggested improving data collection methods and model selectionPoor dataset quality significantly hampers predictive abilityDeliberately created dataset limits realism and applicabilityS. Rajmohan et al.T-SMOTE algorithm for time-series data oversamplingOutperformed competitors in temporal-oriented oversamplingImproved performance in time-series classificationHighlighted the potential for enhancing data preprocessing methodsLimited application in diverse contexts limits broader impactFocused primarily on temporal data, limiting applicability to static datasetsH. He et al.ADASYN for imbalanced learningImproved learning effectiveness for challenging classesAchieved higher accuracy for minority classesStressed the importance of handling imbalanced datasets effectivelyGeneralizability to other datasets remains uncertainFocused on specific datasets, limiting applicability across different contextsMushtaq Hussain et al.Machine learning for predicting waterborne diseases in PakistanRandom Forest: 60% accuracy for malaria, 77% for typhoidEffective in identifying disease outbreaksRecommended tailored interventions based on localized dataFocused on specific diseases limits the broader applicability of findingsFocused on specific diseases limits the broader applicability of findingsN. Khant et al.Study on climate change impacts on waterborne diseasesClimate change significantly affects the rise of WBDsIdentified correlations between climate factors and disease prevalenceCalled for proactive measures to adapt public health strategiesLack of policy adaptation for climate-related health remains unaddressedFocused on ASEAN countries may limit the understanding of global impactsMithila et al.Economic assessment of climate change on waterborne diseases41.4% reported dysentery, 22.4% increased treatment costsHighlighted economic burdens associated with climate changeUrged for strategies to improve water access and sanitationNeed for comprehensive water access strategies to mitigate impactsLimited geographic focus restricts applicability to other regionsSingh et al.Comprehensive analysis of IoT technologies for greenhouse controlDifferent technologies and sensors can significantly enhance crop production by monitoring environmental parametersIdentified advantages and disadvantages of various communication technologies used in greenhousesSummary of monitoring methods underscores the benefits of smart greenhouses over traditional systems and complexity of their microclimateLack of comparative analysis among existing monitoring and control techniques in greenhouse systemsLimited focus on specific sensor technologies and potential biases in selecting communication methods The literature review summary. Data collection A real-time dataset from which all the water quality characteristics could be determined was required because the research was based on time series forecasting. The West Bengal Pollution Control Board offers abbreviated as WBPCB an information system on water quality that includes water parameter data for all river basins that flow through Bengal along with sampling dates and times, which was a fundamental necessity for the research. Web scraping Online web scraping is a technique for haphazardly gathering data from the Internet. It is a field that is advancing quickly and has as its goal based on a system that transports website component abstractions and stores them in a local database, semantic web vision. To conduct more research, the required data must be scraped from the website and saved in an Excel file or database. Several programming languages may be used for online scraping, but Python was chosen since it contains a package called Beautiful Soup that offers an intuitive foundation for data scraping30. This is the URL of the website’s homepage: http://emis.wbpcb.gov.in/waterquality/viewsampledatacitizen.do. The following webpage contains the data available with water quality parameters, test results, and units for each river station: Proposed real-time data collection The real-time data collection process Figure 3 shows real-time IoT device architecture. Built-in microprocessors process sensor data. Data is wirelessly sent to a cloud server or desktop for processing and storage. The architecture allows real-time monitoring and decision-making for fast data-driven operations. Architecture of IoT device for real-time data collection process. The data collection module is made up of several components, including a GSM module, a real-time database, a Raspberry Pi 4 microprocessor, an analog-to-digital converter, and water quality sensors (Firebase). Analog data about the water quality is transformed into digital form and sent to the Raspberry Pi 4 CPU. The MQTT protocol is used by the Raspberry Pi 4 CPU to transmit data about the perceived water quality to a real-time database (Firebase). The data that has been sensed is organized and contains continuous numeric values31. Initially, real-time data was gathered from several nodes spread across different places using IOT sensor devices. The gathered information is stated numerically as follows: Where represents the dataset and represents the -number of sensor data. Attack detection using H-ANFIS In this section, attack detection is carried out. The proposed methodology predicts whether the black hole attack is available in the node or not with the help of the H-ANFIS method. Initially, the proposed method utilizes the k-medoid algorithm to form clusters based on the sensed data on the sensor node location. After that, the clustered data are analyzed using the ANFIS algorithm. The hybridization process is explained as follows, the starting medoids for the clusters are chosen at random as part of the k-medoid method. Below are the steps of the k-medoid method. Step 1: Let be the set of cluster heads. Step 1: Let be the set of cluster heads. Step 2: To get the clusters, assign each cluster node to the closest cluster head. Now, using the equation, the distance between the cluster heads and the other cluster nodes is calculated using the Euclidean distance (2). Step 2: To get the clusters, assign each cluster node to the closest cluster head. Now, using the equation, the distance between the cluster heads and the other cluster nodes is calculated using the Euclidean distance (2). Here and are the cluster head’s and the cluster nodes’ locations. Add up the separations between each cluster node and the cluster heads. Step 3: After that, randomly choose a cluster node to replace the cluster head node, with the requirement that its residual energy be larger than the sum of all nodes’ residual energies. Step 3: After that, randomly choose a cluster node to replace the cluster head node, with the requirement that its residual energy be larger than the sum of all nodes’ residual energies. Step 4: Get the clustering result by now assigning the cluster nodes to the nearby new cluster head. Next, use Eq. (2) to get the Euclidean distance between the cluster heads and the other cluster nodes. Likewise, total the distances between each cluster node and the cluster heads. Step 4: Get the clustering result by now assigning the cluster nodes to the nearby new cluster head. Next, use Eq. (2) to get the Euclidean distance between the cluster heads and the other cluster nodes. Likewise, total the distances between each cluster node and the cluster heads. Step 5: Stop the procedure if the distances added together to equal the distances added together before. Else, go back to Step 3. Step 5: Stop the procedure if the distances added together to equal the distances added together before. Else, go back to Step 3. After clustering, the sensor node is examined with the help of the Adaptive Neuro-Fuzzy Inference System (ANFIS), which functions as a fuzzy model integrated into the adaptive system’s architecture to support learning and adaptation. ANFIS modeling is much more methodical and less reliant on specialized expertise thanks to this framework. Five layers make up the H-ANFIS. The first layer of the H-ANFIS receives its inputs from the clustered features obtained. The second, third, and fifth layers each have fixed nodes, with layers 1 and layer 4 having adaptive nodes. The attacked sensor nodes may be precisely identified using H-ANFIS. The following equations include the two fundamental rules of H-ANFIS. Rule 1: if is and is then, Rule 2: if is and is then, Where,,, and are fuzzy sets. The values of and represent the sensor nodes. The values of , , , , and are the parameter set. The five-layer function of the H-ANFIS system is explained as follows, Layer 1: Each node in this tier has a node function and is a square node (the membership value of the premise part). Where, denotes the membership function, is the sensor node, and is the linguistic label associated with this node function. Layer 2: This layer’s nodes are all circle nodes with the label which multiply the incoming signals. The firing power of each node’s output corresponds to a rule. Where,. Layer 3: Each node in this layer is circularly labeled (normalization). The a node determines the ratio of the firing strength of the rule’s to the total firing strengths. Where, . Layer 4: This layer’s nodes are all square nodes with node functions. Where, . Layer 5: A circular node with the label serves as the only computes the total output as the sum of all incoming signals for each node in this layer. The above Eq. (9) reflects the ANFIS’s total output, which is comparable to the fuzzy system in terms of functionality. In this way, the attacked sensor node is detected. Handling sensed data In this phase, the sensor data are handled by using a load-balancing method. The obtained sensed data-related characteristics are then reduced using the Modified Principal Component Analysis (MPCA) approach, which is described as follows: Feature extraction In this section, a collection of features is extracted and appropriate parameters for workload evaluation are determined. The set of characteristics is extracted, denoted as S1 for Speed, C2 for Task Cost, W3 for Weight, D4 for Delay, P5 for Transmission Probability, R6 for Number of Requests, M7 for Memory, B8 for Bandwidth, L9 for Load on VM, DS10 for Disk Space, and SD11 for Size of Data. These are identified with suitable parameters for workload evaluation, as expressed in Eq. (3): The feature extraction is mathematically expressed as, Feature reduction using MPCA Here, the MPCA algorithm is used to decrease the number of extraneous characteristics. The principal component analysis (PCA) goal is to minimize the dimensionality of a data set made up of numerous variables that are moderately or strongly associated with one another while maintaining as much variety as possible. The same is accomplished by converting the original collection of changes from one set of variables into another called the primary components. The PCA algorithm is modified in the normalization step using the Gaussian kernel function. This MPCA’s primary goal is to select the best characteristics for improved performance and quicker processing. The MPCA algorithm steps are discussed below. Step 1: Data normalization. Step 1: Data normalization. Use the Gaussian kernel function to normalize the data in the uniformed model at this step using the features. The mathematical representation of the feature’s normalization is as follows: Where, the kernel function is represented as here x represents row value, represents column value, and for the parameter. Step 2: Calculate covariance. Step 2: Calculate covariance. It is used to calculate the covariance matrix. Multi-dimension covariance measurement is used. The following is the covariance equation: Where represents the covariance, for the number of tasks, , represents the row and column value respectively, represents the task’s feature count. Step 3: Compute Eigenvalue. Step 3: Compute Eigenvalue. This method determines the Singular Value Decomposition. It is calculated using the following formula. Where, represent the number of tasks, refers to the row features, and represents the column feature. Step 4: Compute the Eigenvector. Step 4: Compute the Eigenvector. The highest Eigenvalue Eigenvectors are calculated using this method. The formula below will be used to calculate an Eigenvector. Where, represents the covariance, denotes Eigenvalues. Step 5: Get PCA. Step 5: Get PCA. Using the formula below, find the highest Eigenvalue in the PCA. Where denotes Eigenvector and the kernel center is referred as . The MPCA algorithm is used for selection of the feature set. B. Data pre-processing. Data pre-processing is the first and most crucial step in data analysis. It includes transforming raw or unstructured data into a format that can be easily analyzed and interpreted32. The following section discusses key steps involved in data pre-processing. By deleting any inconsistent, noisy, or unnecessary data, filling in any missing values, and fixing unbalanced data issues, the objective is to clean and prepare the data for analysis. Data cleaning The dataset contains 42 columns or features; some of the features are not relevant to the research question and have been removed from the dataset. The final dataset used for analysis and forecasting consists of relevant 17 data columns. The features used for analysis are: ‘Turbidity’, ‘Sample Date’, ‘Sample Time’, ‘Water Body’, ‘Ammonia-N’, ‘Nitrate-N’, ‘pH’, ‘Total Coliform’, ‘Calcium’, ‘Chloride’, ‘Fluoride’, ‘Phosphate-P’, ‘Potassium’, ‘Sodium’, ‘Sulphate’, ‘Total Alkalinity’, ‘Total Dissolved Solids (TDS)’, ‘Total Hardness as CaCo3’, ‘Total Suspended Solids (TSS)’. The features in the dataset contain non-numeric and invalid values. It contains strings like “BDL”, “BDKL”, “BDl”, “NDL”, “NT”, and “bdl”, which represent below detection limits or non-detectable values. These values are replaced with ‘0.0’. Similarly, data columns having values that are “Nil”, “x”, or “NaN” are replaced with the empty string. Instances like “0.196, 0.196,” and “0:196” are replaced with correct instances. These features are then converted to a float datatype, with any remaining non-numeric values set to ‘None’. This pre-processing is necessary to ensure that features contain only valid numerical values. Missing values The instances in the dataset where values are expected but the ‘None’ type was found are classified as missing values32. It is necessary to address the missing values instead of eliminating them, because it may lead to the removal of a feature in a model. From Table 2 shows water quality parameter data rows with missing values. It indicates how much missing data each parameter has, which may affect analysis and model predictions. Understanding the constraints is necessary for improving data quality and accuracy. Table 2Number of data rows having missing values for following water parameters.ParametersMissing valuesAmmonia-N1553Nitrate-N913pH29Total Coliform948Calcium1558Chloride1433Fluoride1501Phosphate-P1457Potassium1448Sodium1443Sulphate1462Total alkalinity1455TDS1351Total hardness as CaCo31452TSS982Turbidity1482 Number of data rows having missing values for following water parameters. Interpolation The linear interpolation method is used to estimate values between two known values in a time series dataset. It considers a straight line to estimate an unknown value based on the two nearest known values33. Suppose we have two data points: day1 with x-coordinate x1 and y-coordinate y1, and day3 with x-coordinate x3 and y-coordinate y3. To estimate the value of y on a day between day 1 and day 3, denoted as x, we can use linear interpolation to find an approximate value of y. The formula for linear interpolation is: Here, y1 is the y-value on day1, y3 is the y-value on day3. x1 is the x-value on day1, x3 is the x-value on day3. x is the x-value of the day we want to estimate the y-value for. Labelling data The dataset doesn’t include target class. For classification and oversampling of data, we require the Labelling of data rows or Target Classes. Table 3 shows essential water quality indicators, their limitations, and the health hazards of exceeding them. Concerning Table 3, there are 7 Class Labels named ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, and ‘G’. These class labels represent the associated diseases that can be caused due to water parameters. The process initializes with new columns named ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, and ‘binary_code’ to 0. The four loops then iterate through each row of the data frame using the index () method. Table 3Water parameters with permissible range with associated diseases and class label.SrParameterUnitMax permissible rangeAssociated diseasePeriodClass label1Total ColiformPPM0Gastrointestinal diseases like cholera, diarrhea, hepatitis1 week (3–7 days)ATurbidityNTU3Gastrointestinal diseasesSulphatePPM250Diarrhea (laxative) effect and taste problem.AlkalinityPPM20–200Gastrointestinal issues and skin irritations2Total Dissolved SolidsPPM300–500Kidney diseases156– 365 weeksBTotal suspended SolidsPPM50Kidney diseases3FluoridesPPM1.5Fluorosis (dental problem)200–365 weeksCPH–6.5–8.5Dental corrosion104–208 weeks4SodiumPPM20Stroke, heart failure, osteoporosis, stomach cancer and kidney disease156–520 weeksDTotal hardness as CaCo3PPM20–120Cardiovascular problems, diabetes, reproductive failure, neural diseases, and renal dysfunctionPotassiumPPM< 12Heart disease, coronary artery disease, hypertension, diabetes, adrenal insufficiency, pre-existing hyperkaliemia5PH7-8.5Metabolic alkalosis2–3 weeksE6AmmoniaPPM0.5Convulsions26–50 weeksF7ChloridesPPM250Bladder cancer520–1040 weeksG8NitratePPM300–500Blood disorders (Methemoglobinemia)260–520 weeksH Water parameters with permissible range with associated diseases and class label. For each row, it checks the values of certain columns against certain thresholds, and if the conditions are met, it assigns a value of 1 to the corresponding column ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, or ‘G’. Figure 2. explains the mechanism of the labeling data. Further the values of the ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, and ‘G’ columns to integers, and leave the ‘binary_code’ column unchanged. Finally, the ‘binary_code’ is converted into an equivalent integer representation, which describes the target class of the data row. Figure 4 depicts the method of labelling data. Change the values of the ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, and ‘G’ columns to integers while keeping the ‘binary_code’ column intact. Finally, the ‘binary_code’ is translated into an equivalent integer representation that specifies the data row’s target class. Data samples labelling. Importance of labelling data in the following steps: Step 1: Create 8 new columns named A, B, C, D, E, F, G, binary_code, and class in the DataFrame. Step 1: Create 8 new columns named A, B, C, D, E, F, G, binary_code, and class in the DataFrame. Step 2: Initialize all the values in these columns as 0. Step 2: Initialize all the values in these columns as 0. Step 3: Set the disease class label to ‘1’ if the corresponding data values are not within the permissible range. Step 3: Set the disease class label to ‘1’ if the corresponding data values are not within the permissible range. The above step gives Target Class. A data row can be associated with multiple diseases as represented in Fig. 4. Therefore, it makes the research question a multi-labeled classification problem. The objective of the research required a multi-class classification problem. Step 4: Combine the disease class labels into a single string and convert the data values into binary. Step 4: Combine the disease class labels into a single string and convert the data values into binary. Step 5: Convert the binary representation into decimal form. Step 5: Convert the binary representation into decimal form. Step 4 merges all the class labels into a string representing binary form and then Step 5 converts it to decimal representation representing Target Class. Thus, the problem is now a multi-class classification. After following the above-mentioned steps to label the data 27 different classes were formed. Out of 27 classes Class Label mentioned in the following Table 4 is utilized for the detection, classification, and forecasting of diseases, and the rest Class Labels are neglected or deleted. Table 4Class label used for classification.Class labelNumber of data rows0688022624185369283151042412425142744252 Class label used for classification. TS-SMOTE Time-Series Synthetic Minority Oversampling Technique named TS-SMOTE is a novel hybridized SMOTE developed for oversampling time-series data to solve imbalance problems in the dataset. TS-SMOTE uses the concepts of ADASYN and KNN. After labeling the data, it can be observed that the dataset contains an unequal distribution of data classes. Thus, creating the problem of an unbalanced dataset. The class having maximum number of data tuple is the class considered as majority, whereas the minority class is any other class. As represented in Table 3, the majority class can be considered the majority class, while the rest are considered the minority class. Requirement for TS-SMOTE technique Time series data often do not have independent and identically distributed data (IID), which is what SMOTE presumes. SMOTE has the potential to destabilize the normal correlation structure that exists between time series data and prior and subsequent data points. Time series data are usually organized chronologically34, and the synthetic data produced by SMOTE could not maintain this order, producing data points that are implausible and erroneous. By interpolating between current samples in the feature space, SMOTE creates synthetic samples. SMOTE may provide samples that are unrepresentative of the underlying process, and the feature space may not be the best place for time series data35. SMOTE may sometimes produce artificial samples that are very similar to the actual samples, which may cause overfitting and a delusion of enhanced performance36. Features of time-series dataset A time series dataset has to have certain qualities or characteristics to be used with TS-SMOTE procedures. Here are some crucial aspects to take into account: The dataset should be time-ordered, with observations being collected over time at regular intervals. The dataset should be time-ordered, with observations being collected over time at regular intervals. Time series datasets may either be univariate (i.e., one variable recorded across time) or multivariate (i.e., multiple variables recorded over time). Time series datasets may either be univariate (i.e., one variable recorded across time) or multivariate (i.e., multiple variables recorded over time). A dataset should have an unbalanced class distribution if one or more classes are underrepresented in comparison to other classes. A dataset should have an unbalanced class distribution if one or more classes are underrepresented in comparison to other classes. Optimal time series data should be stable, which means that its statistical characteristics—like mean and variance—remain consistent across time. Before using TS-SMOTE methods, the data may need to be transformed or preprocessed if it is not stationary. Optimal time series data should be stable, which means that its statistical characteristics—like mean and variance—remain consistent across time. Before using TS-SMOTE methods, the data may need to be transformed or preprocessed if it is not stationary. There should be sufficient data to properly reflect the target variable, and the target variable of interest should be explicitly stated. There should be sufficient data to properly reflect the target variable, and the target variable of interest should be explicitly stated. If the dataset is multivariate, there may be variable correlations that should be considered while using TS-SMOTE methods. If the dataset is multivariate, there may be variable correlations that should be considered while using TS-SMOTE methods. To employ TS-SMOTE methods successfully, there must be enough samples present in the minority class to produce synthetic samples without overfitting. To employ TS-SMOTE methods successfully, there must be enough samples present in the minority class to produce synthetic samples without overfitting. The characteristics of a time series dataset will ultimately decide whether time-series SMOTE approaches are suitable and efficient for resolving class imbalance issues. Algorithm of TS-SMOTE. Function TS_SMOTE (month_data): # Assign Year. Function KNN (features, year): # Loop from January to December. Repeat while (month1, 2, 3, …,12): TS_SMOTE (month_data). Train the KNN Model (features as input and year as target class). KNN (features, year). Equation (16) is used for Threshold Calculation it calculates the threshold as the proportion of minority class instances to those belonging to the dominant classes. If the threshold is less than , continue with the SMOTE algorithm. Otherwise, no further action is needed. Equation (17) is used to generate data points in the SMOTE Algorithm. TS_SMOTE (month_data) The TS_SMOTE function is a key component of the algorithm and is responsible for generating synthetic data points to address the class imbalance in the dataset. It takes a dataset containing feature values and target class information for a specific month. The function begins by splitting the data into training and testing sets. It then calculates a threshold based on the ratio of the minority class to the majority class instances. If the threshold is below a certain value, the function proceeds with generating synthetic data. To generate synthetic data, the function computes the dominance of the majority class for each instance and normalizes it to obtain . These dominance values are stored in the list. The function then determines the count of synthetic data points to be generated based on the dominance values and a scaling factor . For each desired synthetic data point, it selects a minority instance and a randomly chosen other minority instance . It employs the mixing parameter to interpolate between the two instances, resulting in a synthetic data point . These synthetic points are appended to the original dataset. Figure 5 depicts the TS-SMOTE method phases. This approach uses synthetic data to address class imbalances in time series data. Illustration of the process followed in the TS-SMOTE technique for generating synthesized data. KNN (features, year) The KNN function is used to train a K-nearest neighbors (KNN) model and assign a year label to the newly synthesized data points. It takes the features as input and the year as the target class. The function first determines the value of K for the KNN model. For each synthesized data point, it calculates the Euclidean distance between the feature values of the synthesized point and the existing data points . The distances are sorted in ascending order. The function then selects the nearest neighbors based on the sorted distances. The majority class among these neighbors is determined, and the corresponding year is assigned to the synthesized data point. Loop from January to December This part of the algorithm involves iterating over the months of the year. Within each iteration, a data frame is created, containing data instances belonging to the current month. The TS_SMOTE function is called with this month-specific data to generate synthetic data points and handle class imbalance. Subsequently, the KNN model is trained using the features and year labels, and the KNN function is invoked to assign year labels to the newly synthesized data points. These functions collectively form an algorithmic framework for addressing class imbalance in time-series data. TS_SMOTE generates synthetic data points, while the KNN model is utilized to classify these points based on the majority class among their nearest neighbors. This iterative process is performed for each month, contributing to a balanced dataset for further analysis and modeling. Advantages of TS-SMOTE Maintains time order of the Dataset. Maintains time order of the Dataset. Works for univariate and multivariate Datasets. Works for univariate and multivariate Datasets. It is less suspectable to Overfitting after Augmentation. It is less suspectable to Overfitting after Augmentation. It is less prone to class overlapping or noise as it uses the concept of ADASYN. It is less prone to class overlapping or noise as it uses the concept of ADASYN. D. MOD-SMOTE. Algorithm of MOD-SMOTE: # Function to remove outliers from the dataset. Function remove_outliers (dataset) (19) # Function for removing duplicates. Function drop_duplicates(dataset) (20) # Main function for oversampling using M-SMOTE. Function mod_smote(dataset, y) (21) # Loop through each minority class. # Perform oversampling using MOD-SMOTE. # Drop the duplicates. The combined code includes three functions: remove_outliers Function (19) This function removes the outliers from the input dataset using the z-score method. Removing outliers can improve the accuracy of machine learning models since outliers can have a huge influence on the performance of models that rely on distance-based calculations. mod_smote Function (21) This function uses MOD-SMOTE, a variant of the SMOTE algorithm, to oversample the minority classes in an imbalanced dataset. Oversampling can improve the accuracy of machine learning models by increasing the representation of minority classes in the training data. drop_duplicates Function (20) This function removes any duplicate rows from the input dataset. Removing duplicate rows can improve data quality, computational efficiency, and simple data management. By combining these functions, we can preprocess the input dataset by removing outliers, oversampling minority classes, and removing duplicate rows in a single step. This can save time and improve the accuracy of machine learning models by ensuring that the input data is clean and properly balanced. E. System flow. The flow of the system initiates with Data Collection from WBPCB as shown in Fig. 6. Flow of system. The data is then processed as mentioned in Section III.B 1, 2, and 3. The data augmentation uses the MOD-SMOTE technique for Classification and TS-SMOTE for Forecasting as mentioned in Section III.D and Section III.C respectively. Then the pre-processed data is stored in the cloud database. Using the model developed it makes predictions and serves the users through the Web Application. Results and discussions In this section, we examine the experimental results of the proposed IoT-based Automated System for Water-related Disease Prediction. The proposed system is implemented using the Python platform. For performance evaluation, the system utilizes the WBPCCB dataset. This data set comprises samples collected on hourly average. From the dataset, 70% of the data is used for training, 15% for validation, and the remaining 15% for testing. Analysis of Data Scrapped for water quality parameters from West Bengal Pollution Control Board (WBPCB) Website–Table 1 represent the number of missing/null values detected in the scrapped data from the WBPCB Website. The analysis of the following data shows that either faulty techniques/systems/devices are used, or the collection of water parameters is not uniform. Numerous parameters were found to have null values in the high range which also includes outliers and extreme values. Table 5 represents the number of data samples that can cause the diseases as represented in Table 3 diseases class. Table 5Data samples exceed the permissible range and can cause associated diseases.Class01A10,66352B10,62689C10,68035D91281587E90351680F95101205G10,7141 Data samples exceed the permissible range and can cause associated diseases. The following analysis is done after filling in the missing values discussed earlier with the interpolation method. Above Table 5 represent that the following data Sample can cause the diseases mentioned in a particular Class. While ‘0’ represent the water parameters in the permissible range and cannot cause the associated diseases. Analysis of the data shows that the possibility of diseases associated with Class ‘D’, ‘E’, and ‘F’ are and if the water is consumed untreated it can lead to severe consequences. While rest of the Classes can be considered as negligible as their samples were found in small quantities but can have the same effect as Class ‘D’, ‘E’, and ‘F’. Table 6 shows the data samples that exceeded the acceptable range for several water quality metrics associated with one or more illnesses. Table 6Data samples exceeding the permissible range associated with one or more diseases.Number of Data Columns having parameters values under Permissible RangeNumber of Data Columns having parameters values exceeding the Permissible Range77572958 Data samples exceeding the permissible range associated with one or more diseases. A. MOD-SMOTE. Table 3 represents the data imbalance problem. Therefore, to avoid biases and overfitting of the model. MOD-SMOTE technique mentioned in the above section is used for solving this issue. B. Classification. Figure 7 depicts the step-by-step procedure of using a classification algorithm, from data preparation to generating predicted class labels. Classification algorithm model approach. Random Forest Random forest is one of the popular ensemble techniques to reduce overfitting and increase the generalization of the model. It works by combining multiple decision trees with each decision tree working on a different set of subsets and features and hence the final decision is taken by voting principle37. According to its definition, Random Forest is a general method combination of classifiers that use L tree-structured base classifiers {h (), N = 1,2,3, …, L}, where denotes the input data and {} is a group of distributed random vectors that are all the same and dependent. There are (y), (y), (y), …, (y) decision trees involved in the prediction process, and p represents the choice that received the majority of votes. The phrase “random state” is used in RF to control the sample’s unpredictability during training. AdaBoost For classification and regression problems, AdaBoost machine learning is used. It works by creating a strong learner from several weak ones. In each iteration of the method, the weak learner is trained on the data, and instances that were mistakenly categorized are given more weight to be classified correctly in the following iteration. In the final model, the weak learners are combined, and their weights are determined by how well they did throughout training. AdaBoost has been used successfully in a variety of areas, such as bioinformatics, text categorization, and face recognition. High precision and the ability to handle complex datasets are two of its most famous qualities. The AdaBoost algorithm retains a collection of weights across training data and adapts them after each cycle of poor learning to generate a group of learners who are weak at learning. Weights for the training samples that the present poor learner incorrectly classified will rise, but weights for the examples that were correctly classified would decline38. XGBoost XGBoost, or extreme gradient boosting, is a popular machine learning method for supervised learning problems. It is a strong and effective algorithm that is increasingly used to create prediction models, especially in contests on websites like Kaggle. The gradient boosting theory, which comprises gradually adding decision trees to an ensemble to improve prediction accuracy, forms the basis of XGBoost. With each repetition, the model becomes better at anticipating the leftover faults from the previous iteration. The model then combines the results of each tree to get a result. Up until the model reaches a set number of trees, or until the performance does not noticeably improve, whichever comes first39. One of XGBoost/s key features is its capacity to handle missing information and feature selection. It penalizes complex models through a process called “regularization,” which might help prevent overfitting. It may be used for classification and regression applications and supports a variety of loss functions. XGBoost’s scalability and efficacy are widely known. It is capable of handling enormous datasets with a variety of properties and can operate in parallel on many CPUs and GPUs. Also, it has several optimization techniques, such as the ability to separate continuous features using a histogram-based technique, which might significantly speed up training. In conclusion, XGBoost is a strong and adaptable machine-learning algorithm that can be applied to a variety of predictive modeling issues. Its popularity in competitions and industrial applications has made it an important tool for data scientists and machine learning practitioners. Tables 7 and 8 provide a comparison of classification performance before and after using the MOD-SMOTE approach, including key metrics including precision, recall, F-score, and accuracy. Table 7, which depicts classification without MOD-SMOTE, demonstrates inferior performance owing to unbalanced data, resulting in poor detection of minority classes. In comparison, Table 8 indicates that using MOD-SMOTE results in considerable gains across all measures. This is because MOD-SMOTE balances the dataset by creating synthetic examples for the minority class, resulting in higher model accuracy and more trustworthy predictions. This comparison shows how MOD-SMOTE improves the model’s capacity to accurately categorise under-represented cases, resulting in better overall performance. Table 7Classification without MOD-SMOTE.ModelAccuracyPrecisionRecallF1-scoreRandom Forest99.850.991.000.99AdaBoost64.030.640.640.64XGBoost64.170.660.650.64 Classification without MOD-SMOTE. Table 8Classification with MOD-SMOTE.ModelAccuracyPrecisionRecallF1-scoreRandom Forest99.660.991.001.00AdaBoost99.521.001.000.98XGBoost99.640.720.650.69 Classification with MOD-SMOTE. Figure 8 compares the performance of three classifiers—Random Forest, AdaBoost, and XGBoost—with and without MOD-SMOTE, utilising measures such as precision, recall, F-score, and accuracy. Without MOD-SMOTE, all classifiers have decreased recall and F-scores, with minority class prediction especially difficult owing to data imbalance, while total accuracy may still look good. MOD-SMOTE enhances performance in all parameters, including accuracy, recall, and F-score, suggesting more balanced and accurate categorisation. MOD-SMOTE significantly improves these models’ capacity to accurately categorise both majority and minority classes, suggesting its utility in enhancing classification performance. In comparison, Random Forest has outperformed the other two models. Comparison of classification performance. One of the most important reasons why Random Forest outperforms is because it is an ensemble algorithm that reduces variance by combining the results of several decision trees generated at different bootstrap samples of the learning set, thereby providing better overall prediction accuracy. This model does well on a large number of high-dimensional datasets and adequately handles both numerical and categorical variables. Moreover, Random Forest avoids overfitting to some extent because it uses the average of multiple predictions. For this model demonstrates high precision because it captures complications within such a water quality dataset and even deals with imbalanced datasets by resampling techniques that further improve its robustness in the applicatory world. The very fast execution time mentioned in the time-tracking metric in Table 9 is also another feature that highlights the efficiency of rapid, quick predictions. Table 9Performance of classification model with and without MOD-SMOTE.Execution timeRandom ForestAdaBoostXGBoostBefore Smote0.03140.03660.0439After Smote0.02390.03160.0378 Performance of classification model with and without MOD-SMOTE. The graphical representation of Table 9 is depicted in Fig. 9. Comparison of classification model execution time. C. TS-SMOTE. The frequency of the data samples in the dataset should have a natural time interval of measurement. The frequency of the dataset represents the number of observations made before the seasonal pattern repeats. Therefore, to make the dataset suitable for forecasting TS-SMOTE is used as mentioned in Section III.C. The dataset generated from TS-SMOTE is used further in Forecasting in Section IV.D. D. Forecasting. LSTM Model Figure 10 depicts the layout of a Long Short-Term Memory (LSTM) model, showing essential components such as input gates, forget gates, output gates, and memory cells, which work together to capture long-term relationships in sequential data. Recurrent neural network (RNN) architectures like the LSTM model are designed to recognise long-term relationships in sequential data. When typical RNNs attempt to learn long-term dependencies, they often run into the vanishing gradient problem. This solution overcomes this difficulty. The LSTM does this by including a memory cell and many gates that control the information flow. It has proved effective in a number of applications including natural language processing, audio recognition, and time series analysis and is able to capture long-term dependencies. LSTM networks are particularly useful when the data has complex temporal dynamics. Architecture of LSTM model with its components. The proposed LSTM model The structure of the suggested LSTM network is shown in Fig. 11. Each of the four LSTM layers in the prediction model comprises 64 units. To create an improved forecasting model, the network contains two feed-forward layers after the LSTM layers, one with 32 units and one with only one unit. LSTM network layers. As a result, the suggested model has almost 144,633 trainable parameters, reducing the time to train the model. To train the LSTM-based deep neural network, a dataset of time-series was constructed by creating windows of 90 consecutive precipitation values. Each window consisted of 90 rainfall observations, and the corresponding output value was the 91st value in the dataset, representing the subsequent consecutive observation. In total, 92,450 windows of consecutive rainfall measurements were generated for training the LSTM model. A training set and a testing set were created from the dataset at a ratio of 80:20, respectively. Dataset preparation The system created a windowed time-series dataset with a window size of 90, consisting of 90 consecutive precipitation values in each window. Each window’s input sequence comprised the first 90 values, and the corresponding output was set as the 91st value. This resulted in a total of 92,450 windows of consecutive rainfall measurements. Train-test split The dataset was split into training and testing sets using an 80:20 ratio. Specifically, 80% of the windows (73,960 windows) were allocated for training, while the remaining 20% (18,490 windows) were reserved for testing. Model architecture The implemented prediction model featured four LSTM layers, each consisting of 64 units. Following the LSTM layers, the network included two feed-forward layers: one with 32 units and one with a single unit. This architecture was designed to build an optimized forecasting model. Hyperparameter optimization Hyperparameter optimization techniques were employed to fine-tune the model’s performance. Specific values were chosen for each hyperparameter during the optimization process. Example hyperparameter values: Number of LSTM Layers: 4, Units per LSTM Layer: 64, Units in the First Feed-Forward Layer: 32, Units in the Second Feed-Forward Layer: 1. Model compilation The model was compiled by specifying the necessary components, including the loss function and optimizer. To measure the disparity between the values, the loss function was mean squared error (MSE) was used that were anticipated and those that were actually obtained. With additional default values and a learning rate of 0.001, the Adam optimizer was used. Model training The LSTM model was trained using the prepared training data and the specified hyperparameters. The training process involved running 100 epochs to ensure sufficient training iterations without overfitting. A batch size of 32 was chosen to process 32 samples at each iteration before updating the model’s parameters. Performance evaluation The model’s performance on the testing set was assessed after the training phase. To measure the precision of the model’s predictions, evaluation measures including mean absolute error (MAE) and root mean square error (RMSE) were used. The model’s performance, including accuracy and validation loss, was carefully analyzed to ensure the best results were achieved. Hyperparameter tuning To enhance the performance of the LSTM model, an extensive hyperparameter tuning process was conducted to optimize its configuration further. To effectively explore the hyperparameter space and identify the ideal combination, methods like random search and Bayesian optimization were used. Example hyperparameter tuning using random search: Number of LSTM Layers: randomly selected from2,4,6 (selected value: 4), Units per LSTM Layer: randomly selected from [32, 64, 128] (selected value: 64), Learning Rate: randomly selected from [0.0001, 0.001, 0.01] (selected value: 0.001), Batch Size: randomly selected from [16, 32, 64] (selected value: 32), Number of Epochs: randomly selected from [50, 100, 150] (selected value: 100), Random search efficiently sampled hyperparameter combinations and evaluated their performance, enabling a more targeted exploration., The combination that yielded the best performance, considering accuracy and validation loss, was selected as the optimized hyperparameters for the LSTM model. Iterative refinement To further enhance the model’s performance and address any remaining issues, an iterative refinement process was implemented. Various techniques were applied iteratively to optimize the model’s generalization and prevent overfitting. Example iterative refinement techniques: Regularization: Dropout with a rate of 0.3 was applied to the LSTM layers to improve generalization. Learning Rate Scheduling: If the validation loss did not decrease after 10 epochs, the learning rate was decreased by a factor of 0.01. Early Stopping: To reduce overfitting, training was terminated if the validation loss did not become better after 20 iterations. These refinement techniques were systematically applied, and the model’s performance was assessed at each iteration to determine their impact and select the most effective settings. By incorporating these enhancements to the Hyperparameter Tuning and Iterative Refinement steps, the LSTM model’s training process was further optimized. The hyperparameters were fine-tuned through techniques like random search, allowing for a more comprehensive exploration of the hyperparameter space. Iterative refinement techniques, such as regularization, learning rate scheduling, and early stopping, were applied to optimize the model’s generalization and achieve the best accuracy and minimum validation loss. Evaluation metric In forecasting research and analysis, various evaluation metrics are used to assess the accuracy and performance of forecasted values. Among the commonly used metrics are the Root Mean Squared Error (RMSE), which measures the average magnitude of the forecast errors, the Mean Absolute Error (MAE), which quantifies the average absolute difference between forecasted and actual values, and the R-squared (R2) value, which shows the percentage of the variance in actual values that can be explained by the forecasted values. Additionally, the Mean Forecast Error (MFE) captures the average difference between forecasted and actual values, while the Mean Percentage Error (MPE) and Mean Absolute Percentage Error (MAPE) provide insight into the average percentage difference between forecasts and actual values. Lastly, the Directional Accuracy (DA) metric evaluates the proportion of correct directional forecasts. Table 10 compares the assessment metrics of a normal LSTM model with the proposed LSTM model for predicting the pH parameter, including MAE, RMSE, MAPE, and R² and graphical represented in Fig. 12. Table 10Evaluation metric for forecasted results of proposed model for parameter PH.MetricLSTMProposed LSTMMAE0.50038340.2843849RMSE0.45045660.3404962R20.480812330.5688159MFE−0.15074543−0.0467451MPE−0.02514325−0.0061526MAPE0.105123490.0791365DA0.40.5 Evaluation metric for forecasted results of proposed model for parameter PH. Evaluation metrics: LSTM vs. proposed LSTM. The line graph compares the performance of the LSTM and Proposed LSTM models using various evaluation metrics. The Proposed LSTM model outperforms the LSTM model across most metrics, showing lower errors (MAE, RMSE) and higher accuracy (R2, DA). The above Actual value [7.642, 7.881, 7.552, 7.693, 7.453, 7.894, 7.712, 7.644, 7.568, 7.814, 7.836, 7.678, 7.725, 7.979, 7.538, 7.937, 7.554, 7.399, 7.642, 7.835] and Forecasted value are [7.699, 7.358, 7.918, 7.548, 7.648, 7.271, 7.876, 7.481, 7.736, 7.609, 7.842, 7.426, 7.998, 7.679, 7.563, 7.953, 7.514, 7.378, 7.784, 7.625]. The analysis conducted helps us gain insights into Metabolic Alkalosis, a medical condition characterized by an elevation in the pH level of the body. Metabolic Alkalosis can occur due to various factors but based on the given pH parameter range of 7–8.5 for 2 to 3 weeks, it is concluded that this specific pH range alone cannot be the cause of Metabolic Alkalosis. Table 11 shows the assessment metrics for the proposed model’s predicted fluoride and pH parameters and graphically represented in Fig. 13. Table 11Evaluation metric for forecasted results of proposed model for parameter fluorides and PH.MetricFluoridesPHLSTMProposed LSTMLSTMProposed LSTMMAE0.08348290.07032040.50038340.284384RMSE0.08435350.09134320.45045660.340496R20.07354350.0821230.48081230.568815MFE0.1223430.112939-0.150745-0.04674MPE7.4879547.431589-0.025142-0.00615MAPE8.7546328.5359770.105123490.079136DA0.30.30.40.5 Evaluation metric for forecasted results of proposed model for parameter fluorides and PH. Evaluation metrics for fluorides and PH: LSTM vs. proposed LSTM. The analysis focused on the Fluorides and pH parameters, with a maximum permissible range of 1.5 for Fluorides and 6.5–8.5 for pH if exceed 108–350 Weeks then it can cause Dental Problems. The evaluation metrics indicate the performance of LSTM and Proposed LSTM models in predicting the values for these parameters. The Proposed LSTM model generally shows better performance across most metrics compared to LSTM, with lower MAE, RMSE, and MPE values and higher R2 and DA values. This suggests that the Proposed LSTM model provides improved accuracy and prediction capability for both Fluorides and pH parameters. With reference to Table 12. The analysis focused on two parameters: Fluorides and pH. The evaluation metrics were used to assess the performance of the LSTM and Proposed LSTM models in predicting these parameters. For the Fluorides parameter, the Proposed LSTM model outperformed the LSTM model in terms of MAE, RMSE, R2, MFE, MPE, MAPE, and DA. The Proposed LSTM model achieved lower error values (MAE and RMSE), higher R2 indicating better explanatory power, and higher DA representing improved directional accuracy. These results suggest that the Proposed LSTM model provides more accurate and reliable forecasts for Fluorides. Table 12Study comparison.StudyRandom Forest (%)AdaBoost (%)XGBoost (%) 40 68.99–– 41 81.0070.0080.00 42 98.28–– 43 97.00–– 44 74.26–99.5Proposed model99.6699.5299.64 Study comparison. Similarly, for the pH parameter, the Proposed LSTM model exhibited superior performance compared to the LSTM model across all evaluation metrics. It achieved lower MAE and RMSE values, higher R2 indicating better explanatory ability, and higher DA suggesting improved directional forecasting accuracy. The Proposed LSTM model’s forecasts for pH were more accurate and aligned closely with the actual values. Based on the analysis of the Fluorides and pH parameters, it can be concluded that the Proposed LSTM model demonstrates better predictive capabilities than the LSTM model. The proposed model provides more accurate forecasts for both Fluorides and pH, making it a valuable tool in forecasting these parameters for various applications such as water quality monitoring and healthcare. It’s worth noting that the analysis considered the permissible ranges for Fluorides and pH. For Fluorides, a maximum permissible range of 1.5 was considered, while for pH, the range of 6.5–8.5 was assessed. It was observed that the forecasted values did not exceed these ranges, indicating that the forecasted values are within acceptable limits and not likely to cause dental problems or metabolic alkalosis. These factors could show the improvements of future predictions. First, extend the data set to include extrinsic parameters such as temperature, humidity, or human activity data, which would give a deeper insight into environmental factors that may affect water quality. Later refinements in the procedure for the optimization of hyperparameters could be more advanced techniques like Bayesian optimization, to further improve accuracy. The ensemble learning approach that combines LSTMs with other models such as Random Forests or Gradient Boosting improves the robustness of the predictions. Lastly, the usual ongoing refinement of regularization techniques and use of a more dynamic learning rate schedule during training may avoid overfitting and improve the generalization of the model towards future use on diverse and changing conditions. Overall, the Proposed LSTM model demonstrates promising performance and can be relied upon for accurate forecasting of Fluorides and pH parameters, contributing to effective decision-making and better understanding of water quality and health-related implications. Conclusion In conclusion, the research paper presented a methodology and related research through which water-related diseases can be predicted and forecasted. The research paper’s methodology involved the collection of real-time data and labeling it by the permissible range of the water parameters. For the preparation of the dataset Data Wrangling techniques were performed. A novel TS-SMOTE Data Augmentation Technique was proposed to solve the problem of class imbalance in the dataset. The classification algorithms utilized were Random Forest, AdaBoost, and XGBoost, with Random Forest achieving the highest accuracy at 99.66% also it took the minimum execution time of 0.0239 s. LSTM algorithm was utilized for forecasting water quality parameters, with an MSE value for pH parameter of 0.163. The paper also discussed the IoT device used for collecting real-time data. Extending it, the paper also discussed attack detection using H-ANFIS and the Feature Reduction technique called MPCA. Thus, the research can be used for predicting and preventing water-borne diseases. Along with it, the research can be used for other potential applications like collecting data on water quality, understanding water quality patterns, analyzing weather conditions to optimize water usage, and monitoring the water quality of river basins to identify potential sources of contamination. The research can aid the authorities and the public in cases of water-borne disease outbreaks, find high-risk areas, identify and monitor industrial contamination, monitor and regulate the temperature in aquaculture, and others. Future scope Enhance efficiency of TS-SMOTE method. Enhance efficiency of TS-SMOTE method. Investigate strategies for detecting unusual events. Investigate strategies for detecting unusual events. Improve accuracy of attack detection methods. Improve accuracy of attack detection methods. Apply findings to agriculture and aquaculture. Apply findings to agriculture and aquaculture. Develop and commercialize the IoT-based system. Develop and commercialize the IoT-based system. Overall, the research findings have significant implications for water quality management and disease prediction, highlighting the potential of advanced technologies to address complex environmental and health problems faced by the public. These can be linked with real-time monitoring systems so that the authorities can prevent contamination of water and take preventive measures before contamination occurs. They can help inform decision-makers through actionable insights from predictive models in support of resource allocation and policy-making, such that health outcomes are improved, and water supplies are made safer for communities. Acknowledgements This research was financially supported by Princess Nourah bint Abdulrahman University Researchers Supporting Project number (PNURSP2024R235), Princess Nourah bint Abdulrahman University, Riyadh, Saudi Arabia. Author contributions All authors contributed equally to the conceptualization, formal analysis, investigation, methodology, and writing and editing of the original draft. All authors have read and agreed to the published version of the manuscript. Data availability The datasets used during the current study are available from the corresponding author on reasonable request. Declarations Competing interests The authors declare no competing interests. Footnotes The original online version of this Article was revised: In the original version of this Article, Affiliation 3 contained an error. Full information regarding the corrections made can be found in the correction for this Article. Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations. Change history 1/28/2025 A Correction to this paper has been published: 10.1038/s41598-025-87061-0 References Associated Data Data Availability Statement The datasets used during the current study are available from the corresponding author on reasonable request.