A full-stack Big Data application that predicts diseases from patient-reported symptoms using a Spark-trained Random Forest model, served through a FastAPI backend on a Hadoop/HDFS cluster β with a beautiful React dashboard.
- Overview
- System Architecture
- Features
- Tech Stack
- Project Structure
- Getting Started
- API Reference
- Dataset
- ML Model
- Contributing
- License
The Healthcare Recommendation System is an end-to-end Big Data project that combines machine learning, distributed computing, and modern web development to assist users in identifying potential diseases based on their symptoms and providing actionable medical recommendations.
The system uses Apache Spark MLlib to train a Random Forest classifier on a symptom-disease dataset. The trained model is stored in HDFS and served at inference time via a FastAPI REST API. A React frontend provides an intuitive symptom checker dashboard with confidence scores, disease descriptions, and medical precautions.
β οΈ Disclaimer: This system is for educational and research purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare professional.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER BROWSER β
β React + Vite Frontend β
β (Symptom Checker Dashboard) β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β HTTP / REST API
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (Python) β
β Disease Prediction & Recommendation API β
β Running on Docker β
βββββββββββββ¬ββββββββββββββββββββββββββββββββ¬ββββββββββββββββββ
β PySpark β CSV files
βΌ βΌ
βββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β Apache Spark β β Recommendation Data β
β (ML Inference) β β (Descriptions/Precautions)β
β spark-master β βββββββββββββββββββββββββββββ
β spark-worker β
βββββββββββββ¬ββββββββββββ
β HDFS Read (Model & Labels)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Apache Hadoop HDFS Cluster β
β NameNode βββββββββ DataNode β
β /healthcare/models/random_forest (RF Model) β
β /healthcare/models/label_mapping (Parquet) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Additional Services:
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ
β Apache Hive β β Jupyter β β PostgreSQL β
β (Metastore) β β Notebook β β (Hive Metadata) β
ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ
- π€ AI Disease Prediction β Random Forest model trained with Apache Spark MLlib on 130+ symptoms
- π Confidence Scoring β Each prediction includes a confidence percentage
- π Medical Recommendations β Automatically retrieves disease descriptions and precautionary measures
- π¬ Big Data Infrastructure β Full Hadoop/HDFS cluster with Apache Spark for distributed ML
- π Jupyter Integration β Interactive notebook environment connected to the Spark cluster
- π Apache Hive β SQL-on-Hadoop metastore for structured data exploration
- π¨ Modern React UI β Built with React 19, React Router, and Recharts for data visualization
- π³ Fully Dockerized β One-command deployment with Docker Compose
| Layer | Technology |
|---|---|
| Frontend | React 19, Vite, React Router, Recharts, Axios |
| Backend API | FastAPI, Uvicorn, PySpark |
| ML Framework | Apache Spark MLlib (Random Forest) |
| Distributed Storage | Apache Hadoop HDFS 3.2.1 |
| Data Warehouse | Apache Hive 2.3.2 |
| Metastore DB | PostgreSQL 13 |
| Notebook | Jupyter PySpark (Spark 3.3.0) |
| Containerization | Docker, Docker Compose |
healthcare-project/
βββ π docker-compose.yml # Full stack orchestration
βββ π hadoop.env.example # Hadoop/Hive environment template
β
βββ π backend/ # FastAPI Python backend
β βββ π Dockerfile
β βββ π main.py # App entrypoint & middleware
β βββ π requirements.txt
β βββ π routes/
β β βββ π predict.py # POST /api/predict
β β βββ π recommend.py # GET /api/recommend/{disease}
β βββ π services/
β β βββ π model_service.py # Spark ML model loader & inference
β β βββ π recommend_service.py # CSV-based recommendation lookup
β βββ π utils/
β βββ π spark_session.py # Spark session factory
β
βββ π frontend/ # React + Vite frontend
β βββ π index.html
β βββ π vite.config.js
β βββ π .env.example
β βββ π src/
β βββ π App.jsx
β βββ π pages/
β β βββ π Home.jsx # Landing page
β β βββ π Diagnosis.jsx # Symptom checker dashboard
β βββ π components/ # Reusable UI components
β βββ π api/ # Axios API client
β
βββ π notebooks/ # Jupyter notebooks for ML training
βββ π scripts/ # Spark job scripts
βββ π data/ # Raw CSV datasets (gitignored)
βββ π models/ # Trained ML artifacts (gitignored)
Make sure you have the following installed:
- Docker (v20.10+)
- Docker Compose (v2.0+)
- At least 8 GB RAM available for Docker (Hadoop + Spark are memory-intensive)
- Node.js 18+ (for local frontend development only)
1. Clone the repository
git clone https://github.com/EZZERBOUTIABDELHAK/Healthcare-Recommendation-System.git
cd Healthcare-Recommendation-System2. Configure environment variables
# Copy and fill in the Hadoop/Hive configuration
cp hadoop.env.example hadoop.env
# Configure the frontend API URL
cp frontend/.env.example frontend/.env3. Edit hadoop.env with your Hive metastore password:
HIVE_SITE_CONF_javax_jdo_option_ConnectionPassword=your_secure_password4. Edit frontend/.env with your backend URL:
VITE_API_URL=http://localhost:8001| File | Purpose |
|---|---|
hadoop.env |
Hadoop, HDFS, YARN, and Hive cluster configuration |
frontend/.env |
React app environment (API base URL) |
Start all services with Docker Compose:
docker compose up -dThis will spin up:
| Service | URL | Description |
|---|---|---|
| React Frontend | http://localhost:5173 |
Main web application |
| FastAPI Backend | http://localhost:8001 |
REST API + Swagger docs |
| Spark Master UI | http://localhost:8082 |
Spark cluster dashboard |
| Spark Worker UI | http://localhost:8081 |
Worker node metrics |
| HDFS NameNode UI | http://localhost:9870 |
Hadoop file system browser |
| Hive Server UI | http://localhost:10002 |
Hive web interface |
| Jupyter Notebook | http://localhost:8888 |
PySpark notebooks |
Jupyter Token:
healthcare123(change this indocker-compose.ymlbefore deploying publicly)
Run the frontend in development mode (optional):
cd frontend
npm install
npm run devCheck service health:
docker compose ps
docker compose logs backend --tail=50Stop all services:
docker compose downThe API is auto-documented at http://localhost:8001/docs (Swagger UI).
Health check endpoint.
Response:
{ "status": "Healthcare API is running" }Predict a disease from a list of symptoms.
Request Body:
{
"symptoms": ["fever", "headache", "fatigue", "nausea"]
}Response:
{
"disease": "Malaria",
"confidence": 94.5,
"label": 12.0
}Get the description and precautions for a predicted disease.
Example: GET /api/recommend/Malaria
Response:
{
"disease": "Malaria",
"description": "An infectious disease caused by Plasmodium parasites...",
"precautions": [
"Consult a doctor",
"Use mosquito repellent",
"Avoid stagnant water",
"Take prescribed antimalarial medication"
]
}The model is trained on the Disease Symptom Prediction dataset from Kaggle, which includes:
- ~4,920 records of symptom-disease pairs
- 42 diseases across various medical categories
- 130+ unique symptoms
- Supporting CSV files for disease descriptions and precautions
The raw data files are not included in this repository (gitignored). Download them from Kaggle and place them in the
data/raw/directory.
Required files in data/raw/:
data/raw/
βββ Training.csv # Main training dataset
βββ symptom_Description.csv # Disease descriptions
βββ symptom_precaution.csv # Medical precautions
The machine learning pipeline is implemented with Apache Spark MLlib:
| Component | Details |
|---|---|
| Algorithm | Random Forest Classifier |
| Features | Binary-encoded symptom vector (130+ features) |
| Training | Distributed training on Spark cluster |
| Storage | Saved to HDFS as Spark MLlib native format |
| Inference | PySpark loaded model served via FastAPI |
Training Workflow (run in Jupyter):
- Load
Training.csvinto Spark DataFrame - One-hot encode symptoms into binary feature vectors
- Label encode diseases
- Train
RandomForestClassifier(100 trees, max depth 10) - Save model + label mapping to HDFS
- Save
symptoms_list.jsonto local/models/directory
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature-name - Commit your changes:
git commit -m 'feat: add your feature' - Push to the branch:
git push origin feature/your-feature-name - Open a Pull Request
Please make sure your code follows the existing style and that any new features are documented.
This project is licensed under the MIT License β see the LICENSE file for details.
Made with β€οΈ by EZZERBOUTIABDELHAK
A Big Data & AI project β Healthcare Recommendation System