Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Disease Prediction from Prescription

This project demonstrates predicting a disease label from prescription records (synthetic dataset provided). It includes data generation, preprocessing, training, inference, and a small Streamlit demo.

Quickstart

  1. Create a virtual environment and install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
  1. Generate synthetic data and run a baseline training:
python data/generate_synthetic.py
python src/train.py --data data/synthetic_prescriptions.csv
  1. Run the demo UI:
streamlit run app/streamlit_app.py

Files

  • data/generate_synthetic.py: creates data/synthetic_prescriptions.csv.
  • src/preprocess.py: preprocessing helper functions.
  • src/train.py: trains baseline model and saves models/model.joblib.
  • src/infer.py: inference helper to load model and predict.
  • src/prescription_ocr.py: OCR extraction and prescription text parsing.
  • app/streamlit_app.py: simple Streamlit demo.
  • requirements.txt: Python package requirements.

Next steps

  • Replace synthetic data with a real prescription dataset if available.
  • Improve feature engineering (drug embeddings, sequence models).
  • Hyperparameter tuning and cross-validation.

OCR mode

The app also supports a prescription-image flow:

  1. Upload a prescription image.
  2. OCR extracts the text.
  3. The extracted text is parsed into structured fields such as age, gender, and medicines.
  4. The existing disease prediction model runs on those structured fields.

For OCR mode, you also need the Tesseract OCR system binary installed on your machine, in addition to the Python packages listed in requirements.txt.

On Ubuntu/Debian:

sudo apt-get update
sudo apt-get install tesseract-ocr

Full Process

This project follows an end-to-end machine-learning workflow. The steps below map to the code in this repository and describe what to run and why.

  • Data collection:: Gather prescription records with fields like age, gender, drug_1, drug_2, drug_3, and a target label disease. Example generator: data/generate_synthetic.py.
  • Exploratory Data Analysis (EDA):: Inspect class balance, missing values, feature distributions, and drug frequency to guide preprocessing and modelling. Run the EDA script: python notebooks/eda.py --data data/synthetic_prescriptions.csv. Output: notebooks/figs/* and notebooks/eda_summary.md.
  • Preprocessing:: Clean data and build features. The pipeline is in src/preprocess.py. It performs basic cleaning, encodes gender, scales age, and converts drugs into a bag-of-drugs representation.
  • Feature engineering & selection:: Create additional features (e.g., drug combinations, counts, temporal features if available). Update src/preprocess.py to add domain-specific features.
  • Train baseline models:: Use python src/train.py --data data/synthetic_prescriptions.csv to train a Logistic Regression baseline and an XGBoost model. Trained artifacts are saved in models/model.joblib.
  • Model tuning & validation:: Use cross-validation and hyperparameter search (e.g., GridSearchCV, RandomizedSearchCV, or Optuna) to improve performance. Evaluate with precision, recall, F1, and confusion matrices.
  • Evaluation & fairness checks:: Check class-wise metrics and ensure no sensitive-group leakage. Analyze per-class recall and precision; consider class weighting or resampling for imbalanced labels.
  • Build inference pipeline:: src/infer.py loads the saved artifacts and provides a Predictor class for batch inference.
  • Demo / API:: A simple demo is in app/streamlit_app.py. It supports both CSV input and OCR on prescription images. For production, wrap Predictor in a REST API using Flask or FastAPI.
  • Reporting & presentation:: Fill report/README.md with methodology, results, and discussion. Prepare slides summarizing the problem, dataset, model, and performance.

Commands recap

# generate data
python data/generate_synthetic.py

# run EDA
python notebooks/eda.py --data data/synthetic_prescriptions.csv

# train
python src/train.py --data data/synthetic_prescriptions.csv

# evaluate
python src/evaluate.py --data data/synthetic_prescriptions.csv --model models/model.joblib

# run demo
streamlit run app/streamlit_app.py

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages