Science and engineering
Machine learning for water quality prediction and uncertainty assessment
Water managers use machine learning to predict parameters such as dissolved oxygen, nitrate and turbidity from cheaper continuous sensors, to fill gaps between lab samples, and to attach prediction intervals that show how far each estimate can be trusted.
How machine learning is used for water quality prediction
Predicting dissolved oxygen
Dissolved oxygen depends strongly on temperature, light and flow, which are measured or modelled far more often than oxygen itself. Models trained on these drivers fill gaps and estimate oxygen where it is not measured.
Real exampleDeep learning for river dissolved oxygen (Zhi et al., Penn State, 2021)Trained an LSTM on daily hydrometeorology and sparse dissolved-oxygen records from 236 minimally disturbed US watersheds; the model learned the decline of oxygen solubility with warmer water.
Modelling lake temperature with physics
Water temperature controls oxygen, algae and habitat. Hybrid models combine physics-based lake models and physical constraints with recurrent networks, so they need less data and behave more plausibly.
Real examplePhysics-guided recurrent networks for lakes (Jia et al., 2018)Combined physics-based model outputs and physical constraints with recurrent neural networks to model lake temperature and quality along depth and time.
Estimating constituents from continuous sensors
Turbidity and conductance sensors record every few minutes, while lab samples are sparse. Regression models calibrated on paired samples estimate constituents such as suspended sediment continuously between samples.
Real exampleUSGS turbidity surrogate guidelines (Rasmussen et al., 2009)USGS guidelines for computing time-series suspended-sediment concentrations and loads from in-stream turbidity sensor and streamflow data with regression models.
Attaching prediction intervals
A prediction interval shows how far each estimate can be trusted, for example during storms or outside the training range. Quantile regression, conformal prediction and probabilistic deep learning all produce them, and their coverage must be checked on held-out data.
Real exampleUncertainty estimation with deep learning (Klotz et al., Hydrology and Earth System Sciences, 2022)Showed that accurate uncertainty predictions can be obtained with deep learning for hydrological prediction and set up a benchmarking procedure for uncertainty estimation.
Can you learn machine learning for water quality?
Yes. Water scientists and engineers can learn the machine learning they need: Python and time-series handling, regression and prediction intervals, tree models, then LSTMs. Knowing sampling methods, sensor drift and water chemistry is what makes the models trustworthy.
- PythonLoad monitoring data from agency portals and plot it by site and time.Learn it in Python
- Time-series handlingJoin continuous sensor records with sparse lab samples by time and site with pandas.Learn it in Data Tools
- Regression and uncertaintyPrediction intervals, quantile regression and checking whether intervals achieve their stated coverage.Learn it in Statistics
- Machine learning modelsRandom forests and gradient boosting, validated on later periods and unseen sites.Learn it in Machine Learning
- Sequence modelsLSTMs for daily forecasting across many sites.Learn it in Deep Learning
Moving into machine learning for water quality
If you already work in the field
Water quality scientists and engineers know sampling methods, sensors and what drives each parameter. Add Python and machine learning, then build a model that estimates a lab-measured parameter from continuous sensors at a site you know, with prediction intervals. Water utilities, environment agencies and consultancies use these models.
If you come from data science or ML
Data scientists should learn water chemistry basics, sampling and laboratory methods, and how sensors foul and drift. Public monitoring data from national agencies such as the USGS is a good place to practise.
Roles that do this workWater quality scientistHydrologistEnvironmental data scientistWater resources engineer
Tools you will use
| Tool | What you use it for |
|---|---|
| dataretrieval | Download USGS and Water Quality Portal data directly into pandas. |
| scikit-learn | Fit regression baselines and quantile models on station data. |
| MAPIE | Add conformal prediction intervals with coverage guarantees to any regressor. |
| LightGBM | Train gradient-boosted and quantile regression models on tabular sensor data. |
| statsmodels | Fit seasonal and linear statistical baselines with uncertainty estimates. |
Public data to practise on
- USGS Water Data for the Nation: Continuous river and groundwater measurements such as temperature, discharge and dissolved oxygen.
- Water Quality Portal: Laboratory water-quality samples from US federal, state and local agencies.
- GEMStat: Global freshwater quality measurements contributed by national monitoring programmes.
Your first project
Download continuous data for one river station from USGS Water Data, predict dissolved oxygen from temperature, discharge and conductance with gradient boosting and MAPIE conformal intervals, and compare it with seasonal linear regression using MAE and interval coverage on a later year.
Common questions
Can machine learning predict water quality?
Yes, for parameters with well-measured drivers such as dissolved oxygen, temperature, turbidity and some nutrients. Predictions are weaker for rare events and for parameters driven by processes the inputs do not capture.
Why do water quality predictions need uncertainty estimates?
Decisions such as changing treatment or issuing advisories depend on how confident an estimate is. Prediction intervals show when a model is unsure, for example during storms or outside its training range.
What is a surrogate in water quality monitoring?
A surrogate is an easily measured variable, such as turbidity or specific conductance, used to estimate a harder one like suspended sediment or chloride through a regression model calibrated on paired samples.
Where can I find water quality data to practise on?
National agencies publish monitoring data, for example the USGS in the United States, the Environment Agency in England and the European Environment Agency's Waterbase.
Courses for these skills
- Practical Machine Learning in PythonCompare losses and models for continuous outcomes.51 published lessons · more lessons in production
- Statistics and Probability for Machine LearningDistinguish confidence, prediction uncertainty and calibration.41 published lessons · all planned lessons open
- Data Tools: NumPy, pandas, Matplotlib and scikit-learnAlign observations by location and acquisition date.23 published lessons · all planned lessons open
- Deep Learning with PyTorchLearn spatial representations for images.Syllabus available · lessons open as produced
New to programming or maths? Start with Python, or follow the machine learning path in order. Published lessons are free to read; compare Free and Pro.