Inspiration

Water pollution is usually found too late. Many places still collect river samples by hand and send them to a lab, and results can take days to weeks. By then the polluted water has moved downstream, sometimes reaching town water intakes and killing fish.

Machine learning can predict water quality, but most models are black boxes that give a number and no reason. Regulators have to justify every field intervention. Even SHAP-based studies usually stop at explaining and never tell the field team what to do next.

We wanted one system that predicts, explains and acts.

What it does

HydroGuard-XAI is a Predict → Explain → Act loop for river pollution risk.

  • Predict: Two Random Forests take 10 water parameters (pH, turbidity, dissolved oxygen, temperature, conductivity, TDS, BOD, COD, rainfall, flow rate). One classifies severity as LOW, MODERATE, HIGH or CRITICAL. The other gives a 0–100 risk score.
  • Explain: Our own pure-Python exact Tree SHAP engine shows how much each parameter pushes the risk up or down, in plain language.
  • Act: The top SHAP drivers are mapped to field actions. High BOD/COD means audit sewage outfalls, and low dissolved oxygen means mobile surface aeration.
  • Early warning: An alert fires when predicted risk rises by 15 points or more, even before it reaches CRITICAL.
  • Dashboard: It shows a risk gauge, SHAP view, trends, a river map and a simulated live IoT stream.

How we built it

The SHAP engine uses the exact decomposition:

$$f(x) = \phi_0 + \sum_{j=1}^{10} \phi_j$$

Here \( \phi_0 \) is the average model prediction and \( \phi_j \) is the contribution of parameter \( j \). The contributions add up exactly to the final prediction.

  • Data: 2,400 synthetic observations across four pollution regimes: clean freshwater, agricultural runoff, urban sewage with hypoxia, and industrial acid inflow. Parameter ranges follow CPCB, US EPA and WHO guidelines.
  • Models: Random Forests with 100 estimators each, tuned by grid search, using a stratified 80/20 split.
  • Backend: FastAPI with Pydantic, served on Uvicorn.
  • Frontend: React 18, TypeScript, Vite, Tailwind CSS and Recharts.

Results

Metric Value
Accuracy 94.58%
F1-score 94.28%
Regression R² 0.9967
MAE / RMSE 1.01 / 1.68

In our test, the early-warning alert fired before the CRITICAL boundary was reached.

Challenges we ran into

  • No real sensor data. We could not deploy sensors across river basins, so we built physically consistent synthetic regimes, such as DO falling as BOD rises in sewage.
  • Exact SHAP without a library. We wrote our own Tree SHAP engine so attribution stays transparent.
  • Explanation to action. Turning SHAP numbers into advice a non-ML field officer can use took careful rule design.
  • Early warning. It had to catch both gradual drift and sudden spikes.

Accomplishments that we're proud of

A complete closed loop from raw readings to a recommended field action, with accuracy and transparency together.

What we learned

  • Accuracy and explainability do not have to be traded off.
  • An explanation only matters if it leads to a decision.
  • Being honest about limits matters. Our data is synthetic and our action rules are heuristic.

What's next

  • Real sensor nodes (ESP32 or Raspberry Pi) over MQTT or LoRaWAN
  • Validation on real river monitoring data
  • Heavy metals and pesticide residues

Built With

Share this project:

Updates

Submission history