Skip to content

devfaizzz/anemia-detection-using-machine-learning

Repository files navigation

🚑 Anemia Detection Using Machine Learning 🚑

An intelligent system for predicting anemia using Random Forest Classification

Python Flask License: MIT


Overview

This project implements a Random Forest Classifier to predict whether an individual is anemic or non-anemic based on their blood-related attributes. The project includes:

  • A Flask-based web application to interact with the model
  • Pre-trained model for predictions
  • A detailed implementation of training, class balancing, and feature importance analysis
  • NEW FEATURE: Upload a blood report image to predict anemia using Google Gemini 2.0 Flash for text extraction

Features

  1. Random Forest Classifier for high accuracy predictions
  2. SMOTE (Synthetic Minority Oversampling Technique) for handling class imbalance
  3. Feature Importance Analysis to identify the most significant contributors to predictions
  4. Simple frontend interface for user input
  5. NEW: Image-Based Prediction – Upload a blood test report image to automatically extract relevant values and get predictions

📊 Performance Evaluation

Model Comparison Analysis

Algorithm Accuracy AUC
Random Forest 99% 99%
Logistic Regression 98% 98%
SVM 90% 90%
KNN 87% 87%

Random Forest Classifier demonstrates superior performance across both metrics.

🏰 System Architecture

System Architecture

The system follows a structured pipeline from dataset handling to model predictions.

📊 Dataset Attributes

  • 💉 Hemoglobin Levels
  • 🔬 Mean Corpuscular Volume (MCV)
  • 🧪 Mean Corpuscular Hemoglobin (MCH)
  • 📈 Mean Corpuscular Hemoglobin Concentration (MCHC)
  • 👤 Gender

⚖️ Class Balance Management

Balanced Dataset

Achieved perfect balance: 801 samples each for anemic and non-anemic classes using SMOTE

🔍 Feature Importance Analysis

Feature Importance

Key Contributors:

  • 🟥 Hemoglobin: 87.0% contribution
  • 👥 Gender: 9.1% contribution
  • 🧬 MCH: 2.7% contribution
  • 💉 Others: 1.2% contribution

Flask Web Application

🛠️ Application Structure

Directory structure:
└── yogeshwaran10-anemia_detection/
    ├── README.md
    ├── Procfile
    ├── app.py
    ├── process_image.py
    ├── requirements.txt
    ├── runtime.txt
    ├── utils.py
    ├── images/
    ├── model/
    │   └── random_forest_classifier.pkl
    ├── static/
    │   └── style.css
    └── templates/
        └── index.html

💻 Installation & Usage

1️⃣ Clone the Repository

git clone <repository_url>
cd anemia-detection-using-machine-learning

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Run the Application

python app.py

Then open the app in your browser at http://127.0.0.1:5000/

📈 Results

  • High Accuracy: Achieved through class balancing and Random Forest optimization
  • 🎯 Precise Predictions: Driven by significant features like hemoglobin levels
  • 📸 New Image Upload Feature: Extracts blood test attributes automatically for prediction

🔮 Future Scope

  • 📊 Expand dataset to include more diverse features
  • 🚀 Implement advanced models like XGBoost or LightGBM
  • ⚖️ Address Feature scaling ⚙️ importance to other features

📸 Screenshots

1. System Architecture

System Architecture

2. Balanced Dataset After SMOTE

Balanced Dataset

3. Feature Importance Analysis

Feature Importance


Outcome Variable Explanation:

The outcome variable in the dataset indicates the final diagnosis or classification for each patient. The outcome is binary, with two possible values:

  • Not Anemic: The patient is not anemic, based on clinical criteria and test results.
  • Anemic: The patient is anemic, suggesting a deficiency of red blood cells or hemoglobin in the blood.

Contributing

Your contributions are welcome! Feel free to:

  • 🐛 Report bugs
  • 💡 Suggest features
  • 🔧 Submit pull requests

🐝 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

anemia sense: leveraging machine learning for precise anemia

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages