A comprehensive final-year engineering project implementing an AI-powered system for urban water demand forecasting, IoT monitoring, and intelligent decision support.
This system combines machine learning and deep learning models with real-time IoT simulation to:
- Forecast water demand using Linear Regression, Random Forest, and LSTM neural networks
- Monitor real-time smart water meters with background IoT simulation
- Predict peak demand periods and water shortages
- Support decision-making with intelligent alerts and rationing recommendations
- Visualize all data and insights through an advanced Streamlit dashboard
final_water_demand/
βββ data/ # Data generation and storage
β βββ dataset_generator.py # Generate realistic water consumption dataset
βββ preprocessing/ # Data preprocessing
β βββ data_processor.py # Handle missing values, normalization, time-series
βββ iot/ # IoT simulation
β βββ iot_simulator.py # Smart water meter simulation with threading
βββ models/ # Machine Learning models
β βββ ml_models.py # Linear Regression & Random Forest
βββ lstm/ # Deep Learning
β βββ lstm_model.py # LSTM for time-series forecasting
βββ forecasting/ # Forecasting engine
β βββ forecasting_engine.py # Area-wise predictions & peak detection
βββ decision_support/ # Decision Support System
β βββ dss.py # Alerts, recommendations, rationing
βββ dashboard/ # Web interface
β βββ dashboard.py # Streamlit dashboard with Plotly
βββ utils/ # Utilities
β βββ config.py # Configuration parameters
β βββ logger.py # Logging setup
βββ models/ # Saved model files (generated after training)
βββ logs/ # Application logs
βββ main.py # Main application orchestrator
βββ requirements.txt # Python dependencies
- Python 3.8+
- Pandas & NumPy - Data manipulation and numerical operations
- Scikit-learn - Machine Learning (Linear Regression, Random Forest)
- TensorFlow & Keras - Deep Learning (LSTM)
- Streamlit - Web dashboard framework
- Plotly - Interactive visualizations
- Threading - Background IoT simulation
cd final_water_demand# Windows
python -m venv venv
venv\Scripts\activate
# Linux/Mac
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtNote: TensorFlow installation may take several minutes.
Run the complete system initialization, training, and demonstration:
python main.pyThis will:
- Generate a realistic 365-day water consumption dataset
- Preprocess and normalize all data
- Train Linear Regression and Random Forest models
- Train LSTM deep learning model
- Initialize the forecasting engine
- Setup Decision Support System
- Start IoT simulator and collect data
- Generate forecasts and alerts
- Save all trained models
Expected Duration: 10-15 minutes (first run with TensorFlow)
After running main.py, launch the interactive dashboard:
streamlit run dashboard/dashboard.pyThe dashboard will open at http://localhost:8501
- Real-time system metrics (supply, demand, utilization)
- Zone status overview
- Current demand by zone visualization
- System utilization gauge
- Start/stop monitoring with background simulation
- Flow rate, tank level, and daily usage for each zone
- Real-time sensor data updates
- Distribution charts
- 7-day and 30-day forecasts
- ML vs LSTM vs Ensemble predictions
- Zone-specific forecasts
- Peak demand identification
- Error metrics (MAE, RMSE)
- Prediction accuracy comparison
- Model performance visualization
- Feature importance analysis
- Active alerts with severity levels
- Current rationing plans
- Priority zones requiring attention
- Water allocation strategies
- Historical demand trends
- Utilization patterns
- Summary statistics
- Time-series analysis
- Fast baseline model
- Interpretable predictions
- Good for trend analysis
- Ensemble method with 100 trees
- Captures non-linear relationships
- Feature importance scoring
- Multi-layer sequence model
- Trained on 7-day sequences
- 7 and 30-day forecasting capability
- Best for complex temporal patterns
- Combines all three models
- Averaging for robust predictions
- Reduces individual model bias
Expected metrics on test data:
| Model | MAE (L/min) | RMSE (L/min) |
|---|---|---|
| Linear Regression | ~130 | ~190 |
| Random Forest | ~95 | ~145 |
| LSTM | ~90 | ~135 |
| Ensemble | ~92 | ~140 |
- CRITICAL (β₯90% capacity): Immediate action required
- WARNING (β₯75% capacity): Monitor and prepare contingencies
- ALERT (β₯60% capacity): Plan for potential restrictions
- NORMAL (<60% capacity): No immediate concerns
- No Rationing: <60% utilization
- Light Rationing (10%): 60-75% utilization
- Moderate Rationing (20%): 75-85% utilization
- Severe Rationing (30%): >85% utilization
- Automatic priority zone identification
- Water allocation strategies
- Emergency action plans
- Public communication guidelines
The system includes a realistic smart water meter simulator with:
- Flow Rate Simulation: Varies by time of day (peak hours: 6-9 AM, 12-1 PM, 6-9 PM)
- Tank Level Monitoring: Real-time level tracking with inflow/outflow
- Daily Usage Tracking: Cumulative water consumption
- Background Execution: Runs in separate thread, non-blocking
- Zone-wise Data: Separate meters for each urban zone
from iot.iot_simulator import IoTSimulator
iot = IoTSimulator(zones=['North', 'South', 'East', 'West', 'Central'])
iot.start() # Starts background monitoring
# Get latest data
data = iot.get_latest_data()
iot.stop() # Stop monitoringThe system generates a realistic 365-day dataset including:
- Date & Hour: Hourly timestamps
- Zone: Urban area (North, South, East, West, Central)
- Population: Zone population (50k-250k)
- Rainfall: Daily rainfall in mm (Gamma distribution)
- Temperature: Hourly temperature with seasonal variation
- Season: Winter, Spring, Summer, Autumn
- Water Usage: Realistic consumption patterns (L/day)
- Seasonal variations (higher usage in summer)
- Daily patterns (peak at noon, low at night)
- Weekly patterns (higher on weekdays)
- Rainfall impact (reduced usage during rain)
- Population-based scaling
Edit utils/config.py to customize:
# Data
ZONES = ['North', 'South', 'East', 'West', 'Central']
TRAIN_TEST_SPLIT = 0.8
# ML Models
LSTM_EPOCHS = 50
LSTM_BATCH_SIZE = 32
# DSS
WATER_SUPPLY_CAPACITY = 5000 # L/min
CRITICAL_THRESHOLD = 0.90
WARNING_THRESHOLD = 0.75
ALERT_THRESHOLD = 0.60
# Dashboard
DASHBOARD_UPDATE_INTERVAL = 10 # secondspython main.py # Complete training pipelinefrom models.ml_models import MLModelsTrainer
from lstm.lstm_model import LSTMForecaster
import joblib
# Load models
lr_model = joblib.load('models/ml_models_lr.pkl')
lstm = LSTMForecaster()
lstm.load_model('models/lstm_model.h5')
# Make predictions
features = [[150000, 10.5, 25.3, 2, 14]] # population, rainfall, temp, season, hour
prediction = lr_model.predict(features)from forecasting.forecasting_engine import ForecastingEngine
forecast_report = forecasting_engine.generate_forecast_report(
all_zones_data=df,
lstm_data=lstm_sequences
)
# Get area-specific forecast
north_forecast = forecast_report['zones']['North']
print(f"North Zone 7-day forecast: {north_forecast['ensemble_forecast']}")from decision_support.dss import DecisionSupportSystem
dss = DecisionSupportSystem(supply_capacity=5000)
analysis = dss.check_demand_vs_supply(
current_demand=3500,
forecasted_demand=4200
)
alert = dss.generate_alert(analysis, zone='Central')
print(alert['message']) # Alert message based on utilization# Install CPU version if GPU unavailable
pip install tensorflow-cpustreamlit run dashboard/dashboard.py --server.port 8502Reduce LSTM_BATCH_SIZE in utils/config.py:
LSTM_BATCH_SIZE = 16 # Reduced from 32β Data Generation: Realistic 365-day water consumption dataset β Preprocessing: Missing value handling, normalization, time-series formatting β ML Models: Linear Regression, Random Forest with evaluation (MAE, RMSE) β Deep Learning: LSTM for 7 and 30-day time-series forecasting β Forecasting Engine: Area-wise predictions and peak demand detection β Decision Support: Automated alerts, rationing plans, priority zones β IoT Simulation: Real-time smart meters with background threading β Dashboard: Advanced Streamlit UI with interactive Plotly charts β Logging: Comprehensive application logging β Model Persistence: Save/load trained models β Ensemble Methods: Combines ML and DL for robust predictions β Production Ready: Clean code, error handling, documentation
This is an educational final-year engineering project.
Developed as a comprehensive AI/ML engineering project demonstrating real-world system design and implementation.
Happy Water Forecasting! π§