An Alternative to Laboratory Testing: Random Forest-Based Water Quality Prediction Framework for Inland and Nearshore Water Bodies

Jianlong Xu, Zhuo Xu, Jianjun Kuang, Che Lin, Lianghong Xiao, Xingshan Huang, Yufeng ZhangWater 2021 · DOI

TL;DR

This paper introduces a novel Random Forest-based framework for predicting water quality parameters like total nitrogen in inland waters and salinity/temperature in nearshore environments. By leveraging readily available water quality indicators or remote sensing data, this approach offers a faster and more cost-effective alternative to traditional laboratory testing, achieving high accuracy in both scenarios.

What Problem Does This Paper Address?

Traditional water quality monitoring often relies on extensive sensor networks and time-consuming laboratory analyses, especially for parameters like total nitrogen (TN). This can be costly, inefficient, and slow to respond to rapidly changing water conditions. For large areas like nearshore waters, deploying dense sensor networks is impractical. The paper addresses the need for more efficient, timely, and cost-effective methods to predict key water quality parameters, particularly TN in inland rivers (crucial for understanding eutrophication) and salinity/temperature in nearshore areas (important for ecological balance).

Methods

The core of the proposed solution is a Random Forest (RF) algorithm, chosen for its superior performance in predicting nonlinear relationships between water quality variables. The framework is designed in three stages:

  1. Data Acquisition and Pre-processing: Raw data is collected from sensors, lab testing, or remote sensing. This data is then pre-processed, including normalization (using Z-score) to handle varying scales of different parameters.
  2. Model Training and Prediction: Various machine learning models (including RF, SVR, KNN, Ridge Regression, MLP, GBRT, and Bagging) are trained on a portion of the data to learn the relationships between independent variables (e.g., temperature, pH, conductivity, or remote sensing bands) and dependent variables (e.g., TN, salinity). RF is selected as the optimal model.
  3. Storage and Display: The trained model is used for prediction, and results are stored and visualized.

A key innovation is the application of RF to predict TN using other water quality parameters as inputs, and its application to nearshore water quality using remote sensing reflectance bands as inputs, demonstrating its versatility. The Google Earth Engine (GEE) platform was utilized for large-scale remote sensing data processing.

Datasets

The study utilized two primary datasets:

  • Inland Water Quality (Lianjiang River): Data collected from a water quality monitoring station in Haimen Bay, Shantou, China. This included parameters like temperature, pH, dissolved oxygen (DO), turbidimetry (Tud), chemical oxygen demand (COD), total dissolved solids (T.D.S), ammonia nitrogen (NH3–N), and total nitrogen (TN). Approximately 1917 sets of data were used, split into 90% for training and 10% for testing.
  • Nearshore Water Quality (Shenzhen Bay): Sentinel-2 remote sensing reflectance data from 2018-2019, along with seawater quality data (temperature and salinity) obtained from the Hong Kong Environmental Protection Department. 147 sets of data were ultimately used after cloud filtering and temporal matching.

Key Insights and Ideas

  • RF's Superiority in Nonlinear Relationships: The study strongly reinforces that water quality parameters often have complex, nonlinear relationships. RF excels at capturing these, outperforming simpler linear models and even other complex models like MLP in certain aspects.
  • Bridging the Gap Between Sensor Data and Lab Data: The framework demonstrates that readily available sensor data (like temperature, pH) can be used to predict parameters that traditionally require expensive and time-consuming lab tests (like TN). This significantly enhances monitoring efficiency.
  • Remote Sensing as a Powerful Tool for Nearshore Monitoring: The successful inversion of salinity and temperature using only remote sensing reflectance bands highlights the potential of satellite data for large-scale, dynamic monitoring of nearshore environments where traditional methods are challenging.
  • GEE for Scalable Analysis: The use of Google Earth Engine proved crucial for handling the large volumes of remote sensing data, enabling efficient processing and analysis for nearshore water quality mapping.

Key Results

  • Inland Water Quality (TN Prediction): The Random Forest model achieved a prediction error rate of 4.9% for total nitrogen concentration in inland rivers. It outperformed other baseline methods, showing improved prediction accuracy by approximately 2 times compared to non-ensemble learning methods.
  • Nearshore Water Quality (Salinity & Temperature Prediction): The Random Forest framework achieved 92.94% accuracy in predicting the salinity of nearshore waters. For temperature prediction, MAE was 1.107 and MAPE was 4.65%, which were lower than other methods. The framework also demonstrated good transferability.
  • Correlation Analysis: While some parameters showed low linear correlation with TN (e.g., DO, pH), the study retained them, hypothesizing potential nonlinear relationships that RF could exploit.

Limitations and Future Work

  • Limitations: The paper acknowledges that while RF performs well, there are still instances of large differences between predicted and true values, particularly for very high TN concentrations in the test set. The accuracy of remote sensing-based predictions can be affected by factors like cloud cover.
  • Future Work: The authors propose transforming the framework into an online water quality monitoring tool. This would involve handling sensor data as streams, enabling dynamic model updates, and filling data inconsistencies due to varying sampling frequencies. This would be a significant step towards real-time, integrated water quality management systems.

Summary updated

Abstract

Water quality monitoring plays a vital role in the water environment management, while efficient monitoring provides direction and verification of the effectiveness of water management. Traditional water quality monitoring for a variety of water parameters requires the placement of multiple sensors, and some water quality data (e.g., total nitrogen (TN)) requires testing instruments or laboratory analysis to obtain results, which takes longer than the sensors. In this paper, we designed a water quality prediction framework, which uses available water quality variables (e.g., temperature, pH, conductivity, etc.) to predict total nitrogen concentrations in inland water bodies. The framework was also used to predict nearshore seawater salinity and temperature using remote sensing bands. We conducted experiments on real water quality datasets and random forest was chosen to be the core algorithm of the framework by comparing and analyzing the performance of different machine learning algorithms. The results show that among all tested machine learning models, random forest performs the best. The data prediction error rate of the random forest model in predicting the total nitrogen concentration in inland rivers was 4.9%. Moreover, to explore the prediction effect of random forest algorithm when the independent variable is non-water quality data, we took the reflectance of remote sensing bands as the independent variables and successfully inverted the salinity distribution of Shenzhen Bay in the Google Earth Engine (GEE) platform. According to the experimental results, the random forest-based water quality prediction framework can achieve 92.94% accuracy in predicting the salinity of nearshore waters.
BibTeX
@inproceedings{xu2021alternative,
  author = {Jianlong Xu and Zhuo Xu and Jianjun Kuang and Che Lin and Lianghong Xiao and Xingshan Huang and Yufeng Zhang},
  title = {{An Alternative to Laboratory Testing: Random Forest-Based Water Quality Prediction Framework for Inland and Nearshore Water Bodies}},
  booktitle = {Water},
  year = {2021},
  doi = {10.3390/w13223262},
}
Figure