# π©Ί Breast Cancer Risk Prediction Project
This repository contains **two related projects** exploring breast cancer risk estimation using machine learning:
1. **Flask Web Application** β a fully functional prototype for predicting breast cancer risk using **multi-modal data** (both *image* and *risk-factor* inputs).
The system uses an **ensemble model**, which blends predictions from different models (e.g., image and clinical data models) to produce a more robust final risk estimate.
2. **Jupyter Notebook β `Breast_Cancer_Risk_Prediction.ipynb`** β a companion experiment that focuses on **image-only** risk prediction.
---
## π Overview
### 1. Flask App β Multi-Modal Ensemble
The web app allows users to upload a mammogram-like image and provide lifestyle or genetic factors to compute an **ensemble probability of risk**.
**What is an ensemble model?**
An ensemble combines multiple independent models (e.g., one trained on mammogram images and another on lifestyle/risk-factor data).
By averaging or weighting their outputs, it reduces noise and improves stabilityβyielding more reliable overall predictions than either model alone.
**Key features**
- Multi-input (image + structured risk-factor data)
- Flask-based front-end with clean Bootstrap UI
- Secure form submission with CSRF protection
- Local file uploads, input forms, and visual results dashboard
- Risk interpretation with contextual explanations and color-coded badges
- Built-in tests (`pytest`), linting (`ruff`), and code formatting (`black`)
- Ready for containerization (Dockerfile + docker-compose.yml)
### 2. Image-Only Model Notebook
The notebook `Breast_Cancer_Risk_Prediction.ipynb` focuses purely on **image classification**.
It trains and evaluates a CNN-based model on mammogram images, generating metrics such as accuracy, loss curves, and confusion matrices.
---
## π Getting Started
### Prerequisites
- Python 3.10+ (recommend using a virtual environment)
- pip, virtualenv, or venv
### 1οΈβ£ Set up the Flask app
```bash
git clone https://github.com/AAdewunmi/Breast-Cancer-Risk-Prediction-Project.git
cd Breast-Cancer-Risk-Prediction-Project/Breast-Cancer-Risk-Prediction-Project
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # (Windows: .venv\Scripts\activate)
# Configure environment
Create a `.env` file based on `.env.example`:
```bash
FLASK_ENV=development
FLASK_DEBUG=1
SECRET_KEY=devkey
UPLOAD_FOLDER=data/uploads
```
# Install dependencies
pip install -r requirements.txtflask runThe app will start at http://127.0.0.1:5000.
Upload an image, fill in risk factors, and view the ensemble prediction dashboard.
pytest -qpre-commit run --all-filesChecks include:
- Ruff (Linter + Fixer)
- Black (Formatter)
- Bandit (Security)
- YAML/TOML/JSON consistency
Breast-Cancer-Risk-Prediction-Project/
β
βββ predictor/ # Flask app package
β βββ __init__.py
β βββ app.py # Flask application factory
β βββ services/ # Inference logic and model stubs
β βββ templates/ # HTML templates (Bootstrap)
β βββ static/ # CSS, JS, images
β βββ tests/ # Unit and integration tests
β
βββ Breast_Cancer_Risk_Prediction.ipynb # Image-only ML model
βββ setup.py
βββ requirements.txt
βββ .pre-commit-config.yaml
βββ pytest.ini
βββ README.md
- Python 3.10+
- Flask
- Bootstrap 5
- Jinja2
- Pytest
- Docker
- Ruff, Black, Bandit (pre-commit hooks)
| Component | Description | Output |
|---|---|---|
| Image Model | Processes uploaded image to estimate visual patterns of risk. | Probability β [0, 1] |
| Risk-Factor Model | Uses user inputs (age, BMI, BRCA, alcohol, etc.). | Probability β [0, 1] |
| Ensemble | Weighted combination of both models. | Combined probability, color-coded interpretation |
Interpretation categories:
| Range | Label | Meaning |
|---|---|---|
| < 10% | Very Low | Minimal model-estimated risk |
| 10β20% | Low | Mild risk, maintain routine screening |
| 20β40% | Moderate | Some elevated indicators, consider clinical discussion |
| 40β70% | High | Elevated probability, follow-up advised |
| > 70% | Very High | Significant model risk; clinical review strongly advised |
β οΈ These outputs are probabilistic and for research or educational use only β not for clinical diagnosis.
| Input Form |
|---|
| Results Page |
|---|
- Unit tests cover inference logic, view rendering, and form handling.
- Integration tests simulate uploads and ensure stable Flask routing.
rufffor linting and auto-fixes.blackfor consistent formatting.- Run checks automatically via pre-commit hooks.
This project was developed with the assistance of OpenAIβs ChatGPT, which supported:
- Code refactoring and docstring generation
- Automated test and CI setup
- UI and UX text suggestions
- Explanation synthesis for interpretability
- Breast Cancer Imaging datasets (for demonstration purposes)
- Flask Documentation: https://flask.palletsprojects.com/
- OpenAI ChatGPT: https://chat.openai.com/
This project is a prototype for educational and research purposes. It does not provide medical advice or diagnosis. Always consult qualified healthcare professionals for clinical assessment.