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
- Random Forest Classifier for high accuracy predictions
- SMOTE (Synthetic Minority Oversampling Technique) for handling class imbalance
- Feature Importance Analysis to identify the most significant contributors to predictions
- Simple frontend interface for user input
- NEW: Image-Based Prediction – Upload a blood test report image to automatically extract relevant values and get predictions
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.
The system follows a structured pipeline from dataset handling to model predictions.
- 💉 Hemoglobin Levels
- 🔬 Mean Corpuscular Volume (MCV)
- 🧪 Mean Corpuscular Hemoglobin (MCH)
- 📈 Mean Corpuscular Hemoglobin Concentration (MCHC)
- 👤 Gender
Achieved perfect balance: 801 samples each for anemic and non-anemic classes using SMOTE
Key Contributors:
- 🟥 Hemoglobin: 87.0% contribution
- 👥 Gender: 9.1% contribution
- 🧬 MCH: 2.7% contribution
- 💉 Others: 1.2% contribution
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.htmlgit clone <repository_url>
cd anemia-detection-using-machine-learningpip install -r requirements.txtpython app.pyThen open the app in your browser at http://127.0.0.1:5000/
- ✅ 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
- 📊 Expand dataset to include more diverse features
- 🚀 Implement advanced models like XGBoost or LightGBM
- ⚖️ Address Feature scaling ⚙️ importance to other features
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.
Your contributions are welcome! Feel free to:
- 🐛 Report bugs
- 💡 Suggest features
- 🔧 Submit pull requests
This project is licensed under the MIT License. See the LICENSE file for details.



