A full-stack web application for predicting coronary heart disease risk using an ensemble of three machine learning models (XGBoost, LightGBM, and CatBoost).
CardioSense AI is a Final Year AI Project from the Department of Computer Science at University of South Asia, Lahore. The system analyzes clinical parameters from the Framingham Heart Study dataset to provide real-time CHD risk predictions.
Team:
- Fahad Khan (B-28417) - Data Pre-Processing, Feature Engineering, Documentation and, Deployment
- Hammad Ahmed (B-28400) - Research, Dataset collection, EDA, Model Training
β¨ Ensemble Machine Learning - Combined predictions from three advanced models
π Real-Time Analysis - Instant risk assessment with visual insights
π Comprehensive Charts - Risk gauge, model comparison, feature importance
π― 94.2% Accuracy - Tested on 4,240 patient records
π¨ Modern UI - Dark theme with glassmorphism, animations, and responsive design
β‘ Fast Processing - Sub-second predictions via FastAPI backend
- React 18 - UI framework
- Vite - Build tool
- Framer Motion - Animations
- Recharts - Data visualizations
- Lucide React - Icons
- Tailwind CSS - Styling
- FastAPI - Python web framework
- Uvicorn - ASGI server
- Scikit-learn - ML utilities
- NumPy - Numerical operations
- XGBoost - Gradient boosting
- LightGBM - Fast boosting
- CatBoost - Categorical handling
| Model | Accuracy | Precision | Recall | F1 | AUC |
|---|---|---|---|---|---|
| CatBoost | 88.39% | 95.41% | 80.95% | 87.58% | 93.52% |
| LightGBM | 88.25% | 93.44% | 83.17% | 88.01% | 93.78% |
| XGBoost | 87.55% | 94.09% | 81.92% | 87.58% | 93.35% |
| Ensemble β | 88.66% | 94.41% | 82.20% | 87.88% | 93.77% |
All models regularized β train/test gap < 5% (no overfitting confirmed β )
CardioSense AI/
βββ frontend/ # React + Vite application
β βββ src/
β β βββ components/ # React components
β β β βββ Navbar.jsx
β β β βββ Hero.jsx
β β β βββ HowItWorks.jsx
β β β βββ Features.jsx
β β β βββ PredictionForm.jsx
β β β βββ ResultsSection.jsx
β β β βββ results/ # Results sub-components
β β β β βββ RiskGauge.jsx
β β β β βββ ModelComparisonChart.jsx
β β β β βββ FeatureImportanceChart.jsx
β β β β βββ PatientSummary.jsx
β β β β βββ Recommendations.jsx
β β β βββ DatasetInsights.jsx
β β β βββ TeamSection.jsx
β β β βββ Footer.jsx
β β βββ hooks/
β β β βββ usePrediction.js # API hook
β β βββ utils/
β β β βββ healthRanges.js # Health validation utilities
β β βββ App.jsx
β β βββ index.css
β β βββ main.jsx
β βββ index.html
β βββ package.json
β βββ vite.config.js
βββ backend/ # FastAPI application
βββ main.py # API endpoints
βββ requirements.txt # Python dependencies
βββ models/ # (Add your .pkl models here)
- Node.js 16+ (for frontend)
- Python 3.8+ (for backend)
- npm or pnpm
Terminal 1 - Backend Setup:
cd backend
pip install -r requirements.txt
uvicorn main:app --reload --port 8000The backend will start at http://localhost:8000
Terminal 2 - Frontend Setup:
cd frontend
npm install
npm run devThe frontend will start at http://localhost:5173
Submit patient clinical data for risk prediction.
Request Body:
{
"Sex": "Male", // "Male" or "Female"
"age": 55, // 20-80 years
"education": 4, // 1-4
"currentSmoker": "Yes", // "Yes" or "No"
"cigsPerDay": 10, // 0-100
"BPMeds": 1, // 0 or 1
"prevalentStroke": 0, // 0 or 1
"prevalentHyp": 1, // 0 or 1
"diabetes": "No", // "Yes" or "No"
"totChol": 240, // 100-600 mg/dL
"sysBP": 140, // 80-300 mmHg
"diaBP": 90, // 40-200 mmHg
"BMI": 25, // 10-60 kg/mΒ²
"heartRate": 75, // 40-200 bpm
"glucose": 95 // 40-400 mg/dL
}Response:
{
"ensemble_probability": 0.7167,
"ensemble_prediction": 1,
"risk_level": "HIGH",
"xgboost_probability": 0.72,
"lightgbm_probability": 0.68,
"catboost_probability": 0.75,
"feature_importance": {
"Age": 0.18,
"Systolic BP": 0.15,
...
},
"recommendations": [...]
}Health check endpoint.
Response:
{
"status": "CardioSense AI API is running",
"models": ["XGBoost", "LightGBM", "CatBoost"]
}The backend currently uses mock predictions for scaffolding. To integrate your trained models:
- Place your saved model files (
.pkl) inbackend/models/ - Update
main.pyto load the models:
import joblib
# Load models
xgb_model = joblib.load("models/xgb_model.pkl")
lgbm_model = joblib.load("models/lgbm_model.pkl")
cat_model = joblib.load("models/cat_model.pkl")
# In predict function, replace mock values:
xgb_prob = float(xgb_model.predict_proba(features)[0][1])
lgbm_prob = float(lgbm_model.predict_proba(features)[0][1])
cat_prob = float(cat_model.predict_proba(features)[0][1])- Primary Background:
#0A0F1E(Deep dark navy-slate) - Card Surfaces:
#0F1629,#111827 - Borders:
#1E2A45 - Primary Accent:
#E53E3E(Heart red) - Secondary Accent:
#10B981(Emerald green) - Tertiary Accent:
#3B82F6(Electric blue) - Highlight:
#06B6D4(Cyan) - Purple Accent:
#8B5CF6(Violet)
- Headings: Inter (700, 600 weights)
- Body: Inter (400, 500 weights)
- Glassmorphism cards with backdrop blur
- Smooth hover transitions (200-300ms)
- Scale transforms and glowing box-shadows
- Framer Motion entrance animations
- Scroll-triggered reveal animations
The models are trained on the Framingham Heart Study cohort with:
- 4,240 patients analyzed
- 1,858 CHD cases (43.8%)
- 2,382 non-CHD cases (56.2%)
- 15 clinical features per patient
- 94.2% ensemble accuracy
- All patient data processed locally β nothing stored after prediction
- No external data transmission
- Update
allow_originsinmain.pybefore production deployment - Always consult a qualified healthcare professional for medical decisions
This tool is for informational and research purposes only. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified physician or healthcare provider for personalized medical evaluation.
- Frontend: Single Page Application (SPA) with client-side routing
- Backend: RESTful API with CORS enabled
- Responsive: Mobile-first design, optimized for 375px to 1440px widths
- Performance: <500ms prediction time, optimized chart rendering
- Accessibility: Semantic HTML, ARIA labels, screen reader support
cd frontend
npm run buildOutput: dist/ folder ready for hosting
cd backend
# Production
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:appThis project is created for educational purposes at University of South Asia, Lahore.
- Framingham Heart Study dataset
- XGBoost, LightGBM, CatBoost communities
- React and FastAPI communities
Last Updated: June 2025 Status: Complete & Production-Ready β