A machine learning-based decision support system for assessing maternal health risk levels during pregnancy. This is a research prototype designed for pilot validation and academic evaluation.
This is a research prototype and NOT a clinical diagnostic tool. The system requires prospective validation before any clinical consideration. All predictions must be verified by qualified healthcare professionals.
This project implements a supervised machine learning system to classify maternal health risk into three categories (Low, Mid, High) based on six clinical measurements. The system is designed to support healthcare providers in identifying high-risk pregnancies for early intervention, while maintaining transparent and explainable predictions.
The primary contribution of this work is the implementation of robust validation methodology that addresses common pitfalls in medical ML research, including data leakage prevention, proper handling of class imbalance, and comprehensive cross-validation.
- Stratified k-fold cross-validation to ensure robust performance estimates
- Proper SMOTE handling within training folds to prevent data leakage
- Comparison of different class imbalance strategies
- Explainable AI using SHAP and LIME
- Web dashboard for interactive risk assessment
- REST API for system integration
- Comprehensive documentation for reproducibility
Source: UCI Machine Learning Repository / Kaggle
Name: Maternal Health Risk Data Set
Original Study: Ahmed et al.
Sample Size: Approximately 1000 pregnant women
Geographic Region: Bangladesh (rural and urban areas)
Collection Method: IoT-based risk monitoring system
The dataset includes six clinical measurements:
- Age - Maternal age in years
- SystolicBP - Systolic blood pressure (mmHg)
- DiastolicBP - Diastolic blood pressure (mmHg)
- BS - Blood sugar level (mmol/L)
- BodyTemp - Body temperature (Fahrenheit)
- HeartRate - Heart rate (beats per minute)
RiskLevel: Three-class ordinal variable
- Low Risk (0)
- Mid Risk (1)
- High Risk (2)
- Limited sample size (n approximately 1000) restricts generalization capabilities
- Single geographic region limits applicability to other populations
- No temporal data - single time-point measurements without pregnancy progression tracking
- Limited feature set - only six measurements, missing many clinically relevant factors
- Potential selection bias in data collection methodology
- Class imbalance with fewer high-risk cases than low-risk cases
- No validation of measurement accuracy or inter-rater reliability
- Python 3.10 or higher
- 2GB free disk space
- Virtual environment (recommended)
-
Clone or download the project repository
-
Create and activate a virtual environment:
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/macOS
python -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- If version conflicts occur:
python fix_dependencies.py- Verify installation:
python check_env.pyAll experiments use fixed random seeds for reproducibility:
- Global seed: 42
- Set in: src/data_processing.py, src/models/train.py, src/models/train_cv.py
- Controls: numpy, random, tensorflow, sklearn operations
For complete reproduction instructions, see run_instructions.txt.
Process the raw dataset with stratified splitting and feature engineering:
python src/data_processing.pyThis performs:
- Data cleaning (duplicate removal, missing value handling)
- Feature engineering (PulsePressure, BodyTemp_C)
- Stratified train-validation-test split (70/15/15)
- Feature scaling (StandardScaler, fitted only on training data)
For dissertation and publication, use the robust cross-validation training:
python src/models/train_cv.pyThis implements:
- Stratified 5-fold cross-validation
- SMOTE applied only within training folds (no data leakage)
- Comparison of resampling strategies
- Evaluation of top models (LightGBM, XGBoost, Gradient Boosting)
- Mean and standard deviation reporting for all metrics
- Model selection based on High-Risk recall (clinical priority)
Outputs:
reports/cv_results_summary.csv- Mean ± std for each modelreports/cv_results_folds.csv- Raw fold-by-fold resultsreports/resampling_strategy_comparison.csv- Strategy comparisonmodels/best_model.pkl- Final trained modelmodels/model_metadata.json- Model configuration and performance
Launch the interactive web interface:
streamlit run dashboard/streamlit_app.pyAccess at: http://localhost:8501
The dashboard provides:
- Single patient risk assessment
- Probability distributions across risk levels
- LIME feature contribution analysis
- Batch prediction from CSV files
- Clinical decision support recommendations
Launch the API server:
python src/api/app.pyAccess documentation at: http://localhost:8000/docs
This project implements rigorous validation to ensure results are not optimistic:
- Folds: 5
- Strategy: Stratified to maintain class distribution
- Process: Each sample validated exactly once
- Reporting: Mean ± standard deviation for all metrics
- SMOTE applied only within training folds using imblearn Pipeline
- Validation data never exposed to synthetic samples
- Test set completely held out from all training processes
- Scaler fitted only on training data
Three strategies compared:
- No resampling (baseline)
- SMOTE oversampling (applied within CV folds only)
- Class weighting (native model parameter)
Primary criterion: High-Risk recall
- Rationale: Clinical priority to minimize false negatives in high-risk cases
- Balanced with overall F1 score and accuracy
- Selection based on cross-validation performance, not test set
- Held-out test set (15% of data)
- Used only for final unbiased performance estimate
- Never used for model selection or hyperparameter tuning
Based on stratified 5-fold cross-validation (results will vary slightly due to random initialization):
Top Models: LightGBM, XGBoost, Gradient Boosting
Metrics (mean ± std from 5-fold CV):
- Accuracy: 0.85-0.95 ± 0.02-0.05
- F1 Score (weighted): 0.85-0.95 ± 0.02-0.05
- F1 Score (macro): 0.80-0.90 ± 0.03-0.06
- High-Risk Recall: 0.70-0.90 ± 0.05-0.15
Note: Standard deviations indicate performance variability across folds. Higher variability suggests sensitivity to specific data splits.
For 95% confidence intervals on metrics, use: CI = mean ± 1.96 × (std / sqrt(n_folds))
When comparing models, consider:
- Overlapping confidence intervals indicate no significant difference
- Clinical significance may differ from statistical significance
- High-Risk recall takes priority over overall accuracy
The system provides interpretable predictions through:
- Global feature importance across all predictions
- Individual prediction explanations with waterfall plots
- Shows contribution of each feature to risk assessment
- Local explanations for individual patients
- Feature contributions in raw measurement units
- Identifies factors increasing or decreasing risk
- Association vs Causation: Explanations show statistical associations, not causal relationships
- Approximations: SHAP and LIME provide approximations of model behavior
- Limitations: Explanations may not capture complex feature interactions
- Clinical Integration: Explanations should support, not replace, clinical judgment
- Small sample size (approximately 1000) limits statistical power and generalization
- Single geographic region - trained on Bangladesh population, may not generalize
- Lack of longitudinal data - no tracking of pregnancy progression
- Missing clinical factors - many relevant measurements not included
- Potential bias in data collection and labeling process
- Not validated prospectively - requires real-world validation studies
- No bias evaluation across different demographic groups
- No temporal validation - performance over time unknown
- Limited to six features - does not consider medical history, lab results, imaging
- Class imbalance may affect minority class predictions despite mitigation strategies
- Hyperparameters not exhaustively tuned - focused on default or simple configurations
- Limited model comparison - focused on top 3 models for efficiency
- Single dataset - no external validation dataset
- Synthetic data concerns - SMOTE creates artificial samples that may not reflect real variability
- Not clinically validated - requires regulatory approval before clinical use
- No integration with EHR systems - standalone prototype only
- No monitoring framework - performance degradation detection not implemented
- No audit trail - limited logging for clinical governance
- Privacy not fully addressed - requires HIPAA/GDPR compliance assessment
- Model trained on specific population may perpetuate existing biases
- False negatives in high-risk detection could lead to missed interventions
- Over-reliance on automated predictions may reduce clinical judgment
- Informed consent and patient autonomy must be maintained
- Transparency about model limitations is essential
Before clinical deployment, this system would require:
- Clinical validation studies with prospective data
- Regulatory approval (FDA, CE marking, etc.)
- Bias and fairness evaluation across demographic groups
- Privacy impact assessment (HIPAA, GDPR compliance)
- Clinical governance framework
- Regular performance monitoring and recalibration
- Clear protocols for human oversight
-
Data Collection
- Larger, more diverse dataset from multiple regions
- Longitudinal tracking throughout pregnancy
- Additional clinical features (lab results, medical history, ultrasound)
- Validation dataset from different healthcare settings
-
Methodology
- External validation on independent dataset
- Prospective validation study in clinical setting
- Bias evaluation across demographic subgroups
- Temporal validation to assess model degradation
- Comparison with clinical risk scores (as baseline)
-
Model Enhancement
- Time-series analysis for pregnancy progression
- Ensemble methods combining multiple models
- Uncertainty quantification for predictions
- Calibration analysis for probability estimates
-
Clinical Integration
- Integration with electronic health records
- Clinical decision support workflow design
- Usability testing with healthcare providers
- Patient-facing interface for risk communication
-
Deployment
- Monitoring framework for model performance
- Feedback loop for continuous improvement
- Audit trail for clinical governance
- Privacy-preserving deployment architecture
maternal-risk-project/
├── data/
│ ├── raw/ # Original dataset
│ └── processed/ # Processed data (generated)
├── models/ # Trained models (generated)
├── reports/ # Results and visualizations (generated)
├── notebooks/ # Jupyter notebooks for exploration
├── src/
│ ├── data_processing.py # Data preprocessing pipeline
│ ├── models/
│ │ ├── train.py # Basic training (single split)
│ │ ├── train_cv.py # Cross-validation training (use this)
│ │ └── predict.py # Prediction service
│ ├── explainers.py # SHAP and LIME explanations
│ └── api/
│ └── app.py # REST API
├── dashboard/
│ └── streamlit_app.py # Web dashboard
├── requirements.txt # Dependencies with versions
├── run_instructions.txt # Detailed reproduction instructions
└── README.md # This file
Key dependencies with version constraints (see requirements.txt for complete list):
- pandas (>=2.0.0, <2.3.0) - Data manipulation
- numpy (>=1.24.0, <2.0.0) - Numerical operations
- scikit-learn (>=1.3.0, <1.6.0) - Machine learning algorithms
- tensorflow (>=2.16.0, <2.17.0) - Deep learning (optional)
- xgboost (>=2.0.0, <3.0.0) - Gradient boosting
- lightgbm (>=4.0.0, <5.0.0) - Gradient boosting
- imbalanced-learn (>=0.11.0, <0.13.0) - SMOTE implementation
- shap (>=0.44.0, <0.46.0) - Model explanations
- lime (>=0.2.0.1) - Local explanations
- streamlit (>=1.25.0, <2.0.0) - Web dashboard
- fastapi (>=0.100.0, <1.0.0) - REST API
Version constraints ensure reproducibility and compatibility.
For exact reproduction, document your environment:
- Python version: 3.10+
- Operating system: Windows/macOS/Linux
- Package versions from: pip freeze > environment.txt
Problem: TensorFlow incompatible with NumPy 2.x
Solution:
python fix_dependencies.pyOr manually:
pip uninstall numpy -y
pip install "numpy>=1.24.0,<2.0.0"Problem: Models not trained yet
Solution:
python src/models/train_cv.pyProblem: Raw dataset not downloaded
Solution:
python download_dataset.pyOr download manually from UCI/Kaggle and place at data/raw/maternal_health.csv
This is an academic research project. If you wish to build upon this work:
- Cite the original work appropriately
- Maintain the validation methodology standards
- Document any modifications clearly
- Consider ethical implications of changes
- Test thoroughly before any deployment
See LICENSE file for details.
- Dataset from UCI Machine Learning Repository
- Original study by Ahmed et al.
- Built using open-source scientific Python libraries
For questions about methodology or reproduction:
- Review run_instructions.txt
- Check code documentation
- Review validation methodology section above
This system is for research and educational purposes only. It should NEVER be used as the sole basis for medical decisions. The system:
- Is not a medical device
- Has not undergone clinical validation
- Requires prospective validation studies
- May contain biases from training data
- Should not replace clinical judgment
- Requires qualified medical oversight
All medical decisions must be made by qualified healthcare professionals based on comprehensive clinical assessment.
- Version 1.0 (2026-01-12): Initial release with robust cross-validation methodology
- Ahmed, M. et al. - Original dataset publication
- UCI Machine Learning Repository - Dataset source
- SMOTE: Chawla, N.V., et al. (2002). SMOTE: Synthetic Minority Over-sampling Technique
- SHAP: Lundberg, S.M., & Lee, S.I. (2017). A unified approach to interpreting model predictions
- LIME: Ribeiro, M.T., et al. (2016). "Why Should I Trust You?": Explaining predictions
For complete citations, see dissertation bibliography.