Skip to content

Latest commit

ย 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ’Š Drug Safety Intelligence System

AI-Powered Pharmacovigilance & Risk Assessment Platform

Python XGBoost Streamlit FastAPI License


๐ŸŒŸ Overview โ€ข โœจ Features โ€ข ๐Ÿ“ธ Screenshots โ€ข ๐Ÿ› ๏ธ Tech Stack โ€ข ๐Ÿ“ฆ Installation โ€ข ๐Ÿ‘ฅ Team


System Logo

Transform raw clinical data into proactive patient safety insights โœจ


Web API Data


๐ŸŒŸ Overview

The Drug Safety Intelligence System is an end-to-end, AI-powered pharmacovigilance platform designed to analyze adverse drug events and proactively predict patient harm severity and specific reactions. Utilizing real-world clinical data, the system assists healthcare professionals and clinical researchers in early signal detection and risk assessment.

๐Ÿฅ FDA FAERS Integration - Built on massive real-world relational databases (Year 2025) including DEMO, DRUG, REAC, THER, and OUTC.

๐ŸŽฏ What Makes This System Special?

๐Ÿง  Advanced ML Models

Utilizes highly optimized XGBoost models for both Binary Severity Prediction (ROC-AUC: 85.08%) and Multi-class Reaction Forecasting.

โš–๏ธ Class Imbalance Handling

Programmatically tackles real-world clinical data imbalance using strategic downsampling and rigorous Target/Mean Encoding strategies.

๐Ÿ“Š Global Safety Signals

Mines integrated clinical databases to identify and flag statistically significant drug-adverse event pairs automatically.

โ˜๏ธ Cloud-Optimized Architecture

Refactored from a massive 2GB ensemble to a streamlined ~53MB joblib-compressed model, perfect for strict memory environments.

๐Ÿš€ Dual-Deployment

Features both a beautiful, interactive Streamlit Dashboard for end-users and a robust FastAPI Backend for system integrations.

๐Ÿ› ๏ธ Automated SQL Pipeline

Constructs complex feature engineering matrices directly using SQL Common Table Expressions (CTEs) without overwhelming RAM.


โœจ Features

๐Ÿ“ฑ Core Modules


๐Ÿ”ฌ Patient Risk Analysis
Calculates real-time severity probabilities based on patient profiles

๐Ÿ”ฎ Reaction Forecasting
Predicts the top 3 adverse events a patient might experience

๐Ÿšจ Signal Detection
Interactive database exploring historical drug-reaction reports

โšก Oriva PV API
FastAPI endpoints for seamless frontend/external integration

โš™๏ธ Dual Pipeline
Distinct, rigorous preprocessing strategies for different models

๐Ÿ“ˆ Deep EDA Reports
High-res clinical pattern visualizations and data drift checks

๐Ÿค– Machine Learning Capabilities

Task Algorithm Optimization Performance (Test Set)
๐Ÿ”ด Severity Prediction XGBClassifier (Binary) scale_pos_weight=1.40, tree_method='hist' ROC-AUC: 85.08%
Recall: 77.00%
๐Ÿ’Š Reaction Forecasting XGBClassifier (Multi-class) max_depth=10, compress=9 (~53MB footprint) Accuracy: 72.85%
(Across 20 targets)

๐Ÿ“ธ Screenshots

๐Ÿ’ป Live System Dashboard

Patient Risk Analysis (Matrix A & B) Global Safety Signals Database
Dashboard Preview Safety Signals Tab

๐Ÿ“Š Deep Exploratory Data Analysis (EDA)

Demographics (Age/Weight) Target Imbalance Top 10 Suspect Drugs
Polypharmacy Impact Age by Gender Feature Importance
Therapy Duration Analysis
Temporal Stability (Data Drift)

๐Ÿ› ๏ธ Tech Stack

Data Processing & Pipeline

Technology Purpose
Python Core Programming Language (3.9+)
Pandas Clinical Data Manipulation
NumPy Mathematical Operations
SQLite Relational Database Engine

Machine Learning

Technology Purpose
Scikit-learn Preprocessing, Resampling, Metrics
XGBoost Tree-based Classification Algorithms
Optuna Hyperparameter Tuning
Joblib Advanced Model Compression

Deployment & Backend

Technology Purpose
FastAPI High-performance RESTful API
Streamlit Interactive Web Dashboard
GitHub Actions CI/CD Pipeline (Linting)

๐Ÿ“ฆ Installation

๐Ÿ“‹ Prerequisites
  • โœ… Python 3.9 or higher
  • โœ… Git installed
  • โœ… Raw FDA FAERS Dataset (Not included in repo due to size)

๐Ÿš€ Quick Start

# 1๏ธโƒฃ Clone the repository
git clone [https://github.com/GoldenBoy13420/Drug-Safety-Intelligence-System.git](https://github.com/GoldenBoy13420/Drug-Safety-Intelligence-System.git)
cd Drug-Safety-Intelligence-System

# 2๏ธโƒฃ Install dependencies
pip install -r requirements.txt

# 3๏ธโƒฃ Run the Streamlit Dashboard
streamlit run app.py

# 4๏ธโƒฃ Or Run the FastAPI Backend
uvicorn api:app --reload

To rebuild the matrices and retrain the models from scratch:

python main.py

This single entry point will sequentially run:

  1. Database Connection Validation
  2. Deep EDA (eda.py)
  3. Safety Signal Detection (signal_detector.py)
  4. Matrix A & B Construction (preprocessing.py)
  5. XGBoost Model Training & Evaluation

๐Ÿ“ Project Structure

DRUG-SAFETY-INTELLIGENCE-SYSTEM/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“‚ data/                   # Raw FDA data & SQLite DB (Ignored in Git)
โ”œโ”€โ”€ ๐Ÿ“‚ logs/                   # System execution logs (pipeline.log)
โ”œโ”€โ”€ ๐Ÿ“‚ models/                 # Compressed XGBoost .pkl models & Encoders
โ”œโ”€โ”€ ๐Ÿ“‚ notebooks/              # Data integration & experimental notebooks
โ”œโ”€โ”€ ๐Ÿ“‚ reports/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“‚ figures/            # High-res EDA plots & Dashboard Screenshots
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ safety_signals_report.csv
โ”‚
โ”œโ”€โ”€ ๐Ÿ’ป src/                    # Core Modules
โ”‚   โ”œโ”€โ”€ config.py              # System paths and constants
โ”‚   โ”œโ”€โ”€ data_pipeline.py       # Database validation
โ”‚   โ”œโ”€โ”€ eda.py                 # Visual analysis generator
โ”‚   โ”œโ”€โ”€ preprocessing.py       # SQL CTEs and Matrix Building
โ”‚   โ”œโ”€โ”€ model_severity.py      # Binary Classification Pipeline
โ”‚   โ”œโ”€โ”€ model_adverse_event.py # Multi-class Classification Pipeline
โ”‚   โ””โ”€โ”€ signal_detector.py     # Pharmacovigilance Mining
โ”‚
โ”œโ”€โ”€ โšก api.py                  # FastAPI endpoints
โ”œโ”€โ”€ ๐ŸŒ app.py                  # Streamlit UI dashboard
โ”œโ”€โ”€ ๐Ÿš€ main.py                 # Full Pipeline orchestrator
โ””โ”€โ”€ ๐Ÿ“„ requirements.txt        # Cloud dependencies

๐Ÿ‘ฅ Team


Mahmoud Abdelrauf
๐ŸŽฏ AI Engineer / Lead

Ahmed Elabd
๐Ÿ’ป Data Scientist

Abdelrhman Batran
๐Ÿ’ป Data Scientist

๐Ÿ“œ License

This project is licensed under the MIT License.


โญ Support

If you find this intelligence system helpful, please give it a star!

About

End-to-end AI pharmacovigilance platform for predicting adverse drug events and harm severity using FDA FAERS data.

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages