This project implements an end-to-end MLOps Platform for real-time wastewater quality monitoring. It deploys a Soft Sensor (Machine Learning Model) to estimate Biological Oxygen Demand (BOD), a critical metric that typically requires a 5-day laboratory test (
By correlating real-time physical sensors (pH, Conductivity, COD, Flow) with historical biological data, this system provides instant feedback to plant operators, enabling proactive process control.
- Production Engineering: Modular, refactored code structure suitable for Docker/Kubernetes.
- Observability: Real-time tracking of Data Drift (Salinity spikes) and System Latency.
- Regulatory Compliance: Full transparency documentation (
MODEL_CARD.md) aligned with the EU AI Act.
wastewater_project/
├── api/ # FastAPI Deployment & Monitoring Middleware
│ └── main.py # Serves the model + /monitoring/stats endpoint
├── config.yaml # Central configuration (Model types, Paths)
├── data/ # Data storage (Raw & Processed)
├── docs/ # Sphinx Documentation
├── models/ # Serialized Models (.joblib)
├── notebooks/ # R&D and Exploratory Data Analysis
├── src/ # Production Source Code (Refactored)
│ ├── data_loader.py # Robust data ingestion
│ ├── features.py # Feature Engineering (Cyclical Time)
│ ├── model.py # Model Factory (RandomForest/SVM)
│ └── main.py # Automated Training Pipeline
├── MODEL_CARD.md # Regulatory Transparency Document
├── report.md # Executive summary
└── README.md # You are here1. Installation
Clone the repository and install dependencies:
pip install -r requirements.txt
(Dependencies include: fastapi, uvicorn, pandas, scikit-learn, pyyaml, mlflow)
2. Train the Model (Automated Pipeline)
Run the MLOps pipeline to process data, engineer features, and train the model. This reads settings from config.yaml.
python src/main.py
-
Output: Saves a trained model to
models/bod_predictor.joblib. -
Metrics: RMSE ~45 mg/L (Logged to MLflow).
3. Launch the API (Deployment)
Start the FastAPI server to serve predictions and monitor health.
uvicorn api.main:app --reload
-
API Docs: http://127.0.0.1:8000/docs
-
Monitoring Dashboard: http://127.0.0.1:8000/monitoring/stats
The system includes custom Middleware to track production health. Access the /monitoring/stats endpoint to view:
-
Latency: Average inference time (ms).
-
Drift Detection: Monitors input Conductivity and COD.
-
Alerts: Flags "Shock Load" events if predictions exceed 400 mg/L.
This project adheres to Article 13 (Transparency) of the EU AI Act for High-Risk AI Systems.
To handle the biological seasonality of wastewater without creating discontinuities at year-end, we implemented Cyclical Time Encoding:
# Converting linear "Month" into continuous coordinates
df['sin_month'] = np.sin(2 * np.pi * df['Month'] / 12)
df['cos_month'] = np.cos(2 * np.pi * df['Month'] / 12)
This ensures the model understands that December (12) and January (1) are neighbors.
MIT License - Open for educational and operational use.
