Skip to content

Ashwashhere/MedicalMachineLearning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

🩺 Medical Machine Learning: Pneumonia Diagnosis Pipeline

An end-to-end comparative study evaluating supervised learning classifiers, soft-voting ensembles, and computer vision on clinical feature metrics and raw chest X-ray images.

Python NumPy Pandas Scikit Learn Scikit Image Seaborn Matplotlib


Project Overview Visual

📌 Project Overview

This repository investigates the practical application of Machine Learning in diagnosing Pneumonia across two distinct modalities:

  1. Tabular Feature Analysis: Comparative benchmarking of standalone supervised algorithms and multi-tiered Soft-Voting Ensembles built on clinical feature data.
  2. Computer Vision Classification: Automated preprocessing and evaluation of raw 2D chest X-ray images using flattened Support Vector Machine (SVM) classification.

Special emphasis was placed on mitigating class imbalance (class_weight='balanced') to optimize diagnostic recall and minimize critical False Negatives (mislabeled patient diagnoses).


🛠️ Key Technical Highlights

  • Automated Pipelines: Built robust sklearn.pipeline.Pipeline chains combining StandardScaler with classifier models to prevent data leakage during evaluation.
  • Class Imbalance Mitigation: Integrated balanced class weighting across Decision Trees, Logistic Regression, and SVMs to improve recall on the minority class (0.0 / No Pneumonia).
  • Multi-Level Soft-Voting Ensembles: Constructed hierarchical ensembles combining high-performing base models (Random Forest, Logistic Regression, SVM) using soft probability weighting.
  • Computer Vision Pipeline: Preprocessed raw X-ray scans via grayscale conversion (rgb2gray), 128x128 dimensional resizing, 1D array flattening, and standard scaling.
  • Rigorous Cross-Validation: Applied 5-Fold Stratified K-Fold Cross-Validation (StratifiedKFold) across all non-testing partitions to ensure generalization.

📊 Benchmark Model Performance

1. Tabular Clinical Feature Models (Dataset: 583 Observations)

Model Architecture Hyperparameters / Preprocessing Key Metrics (Test / K-Fold CV) Primary Strength
Logistic Regression liblinear, max_iter=150, Balanced 73.1% CV Accuracy (71.6% Test) Strong overall generalization; robust recall
Support Vector Machine (SVM) kernel='rbf', gamma=5, Balanced 71.1% CV Accuracy (71.6% Test) Effective margin separation for complex features
Random Forest Ensemble n_estimators=150, max_depth=5, Balanced 69.2% CV Accuracy (67.2% Test) Reduced overfitting compared to single decision trees
Optimal Hierarchical Ensemble Soft-Voting (Random Forest + SVM + LogReg) 69.8% CV Accuracy (64.7% Test) Best Minority Class Recall & F1-Score
K-Nearest Neighbors (KNN) n_neighbors=7 63.4% CV Accuracy (64.7% Test) Good positive class detection
Decision Tree Classifier max_depth=5, Balanced 60.4% CV Accuracy (60.3% Test) High interpretability
Gaussian Naive Bayes var_smoothing=1e-8 54.1% CV Accuracy (59.5% Test) Fast baseline execution

2. Computer Vision Pipeline (Raw Chest X-Ray Images)

  • Architecture: Support Vector Classifier (kernel='linear', probability=True)
  • Preprocessing: Grayscale transformation, 128x128 spatial resizing, standard scaling
  • Test Accuracy: 75.0%
  • Pneumonia Sensitivity (Recall): 0.99 (99%)

🏗️ Repository & Directory Structure

├── MLPneumonia.py             # Primary Python script / Colab notebook source
├── portfolio_thumbnail.png    # Project visual graphic for portfolio summary
├── pneumonia_raw.csv          # Tabular clinical dataset (raw)
├── chest_xray/                # Raw X-ray image directory (train / val / test)
└── README.md                  # Project documentation

🚀 How to Run Locally

1. Clone the Repository

git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name

2. Install Dependencies

pip install pandas numpy scikit-learn scikit-image seaborn matplotlib

3. Run the Pipeline

python3 MLPneumonia.py

Developed as part of an academic machine learning investigation into AI-assisted medical diagnostics.

About

This project is a machine learning investigation focused on predicting the presence of pneumonia based on patient clinical data and X-ray features. The work is structured as a comparative analysis where multiple classification models are built, evaluated, and optimized to find the most accurate diagnostic tool.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors