Update README.md
Browse files
README.md
CHANGED
|
@@ -5,28 +5,65 @@ emoji: 🩸
|
|
| 5 |
colorFrom: red
|
| 6 |
colorTo: gray
|
| 7 |
sdk: gradio
|
| 8 |
-
sdk_version:
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
#
|
| 14 |
|
| 15 |
-
|
| 16 |
-
The **Hemaclass AI Diagnostics** dashboard is a Phase 4 prototype designed to classify multi-class hematological diseases (Malaria, Sickle Cell Anemia, Co-infections, and Negative cases) using a highly optimized, stacked ensemble machine learning architecture.
|
| 17 |
|
| 18 |
-
##
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
3. **Clinical Recommendations:** Automated WHO-aligned protocol suggestions based on severity (e.g., hyperhemolytic crisis alerts).
|
| 23 |
-
4. **XAI Interpretability:** Local SHAP (SHapley Additive exPlanations) waterfall plots explaining exactly *why* the AI made the decision.
|
| 24 |
|
| 25 |
-
##
|
| 26 |
-
|
| 27 |
-
- **Meta-Learner:** Logistic Regression (Stacking Classifier).
|
| 28 |
-
- **Preprocessing:** MICE Imputation, SMOTE Data Balancing, robust Z-Score Normalization.
|
| 29 |
-
- **Optimization:** ~30 minute Bayesian Search CV (Nested 5-Fold) to guarantee robust generalization without overfitting.
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
colorFrom: red
|
| 6 |
colorTo: gray
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 4.44.1
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
+
tags:
|
| 12 |
+
- medical
|
| 13 |
+
- biology
|
| 14 |
+
- xai
|
| 15 |
+
- malaria
|
| 16 |
+
- sickle-cell
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# Hemaclass AI Diagnostics: Clinical Decision Support System
|
| 20 |
|
| 21 |
+
An explainable ensemble-based diagnostic tool optimized for **Malaria**, **Sickle Cell Anemia (SCA)**, and **Co-infection** classification in Western Kenya.
|
|
|
|
| 22 |
|
| 23 |
+
## 🔬 Model Details
|
| 24 |
+
- **Architecture:** Stacking Ensemble (RF, SVM, XGBoost) with a Logistic Regression Meta-Learner.
|
| 25 |
+
- **Explainability:** Integrated SHAP waterfall plots for local feature importance.
|
| 26 |
+
- **Preprocessing:** MICE Imputation, SMOTE balancing, and Z-Score Normalization.
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
## 🚀 Quick Usage (Inference Code)
|
| 29 |
+
To use this model programmatically, ensure you have your `.pkl` artifacts in the local directory.
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
```python
|
| 32 |
+
import joblib
|
| 33 |
+
import pandas as pd
|
| 34 |
+
import numpy as np
|
| 35 |
+
|
| 36 |
+
# 1. Load Artifacts
|
| 37 |
+
model = joblib.load('ensemble_model.pkl')
|
| 38 |
+
scaler = joblib.load('scaler.pkl')
|
| 39 |
+
imputer = joblib.load('imputer.pkl')
|
| 40 |
+
FEATURES = joblib.load('feature_names.pkl')
|
| 41 |
+
target_names = ['Negative', 'Malaria', 'SCA', 'Co-infection']
|
| 42 |
+
|
| 43 |
+
def predict_patient(data_dict):
|
| 44 |
+
"""
|
| 45 |
+
Input: Dictionary of patient vitals/labs
|
| 46 |
+
Output: Predicted Diagnosis and Confidence
|
| 47 |
+
"""
|
| 48 |
+
# Create DataFrame and align features
|
| 49 |
+
df = pd.DataFrame([data_dict])
|
| 50 |
+
for col in set(FEATURES) - set(df.columns):
|
| 51 |
+
df[col] = np.nan
|
| 52 |
+
df = df[FEATURES]
|
| 53 |
+
|
| 54 |
+
# Preprocess
|
| 55 |
+
X_imp = imputer.transform(df)
|
| 56 |
+
X_scaled = scaler.transform(X_imp)
|
| 57 |
+
|
| 58 |
+
# Inference
|
| 59 |
+
pred = model.predict(X_scaled)
|
| 60 |
+
prob = np.max(model.predict_proba(X_scaled))
|
| 61 |
+
|
| 62 |
+
return {
|
| 63 |
+
"Diagnosis": target_names[pred],
|
| 64 |
+
"Confidence": f"{prob*100:.2f}%"
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
# Example Usage:
|
| 68 |
+
patient_data = {'age': 25, 'hb': 10.5, 'temp': 38.5, 'malaria_rdt': 1}
|
| 69 |
+
print(predict_patient(patient_data))
|