Datasets:
Upload folder using huggingface_hub
Browse files- README.md +128 -0
- data/ear_district_hospital.csv +0 -0
- data/ear_ent_specialist_centre.csv +0 -0
- data/ear_rural_health_centre.csv +0 -0
- generate_dataset.py +247 -0
- requirements.txt +3 -0
- validate_dataset.py +132 -0
- validation_report.png +3 -0
README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
tags:
|
| 8 |
+
- healthcare
|
| 9 |
+
- hearing-loss
|
| 10 |
+
- ear-disease
|
| 11 |
+
- otitis-media
|
| 12 |
+
- ent
|
| 13 |
+
- audiometry
|
| 14 |
+
- sub-saharan-africa
|
| 15 |
+
- lmic
|
| 16 |
+
pretty_name: "Hearing Loss & Ear Disease (CSOM, Audiometry, Hearing Aids, ENT)"
|
| 17 |
+
size_categories:
|
| 18 |
+
- 10K<n<100K
|
| 19 |
+
configs:
|
| 20 |
+
- config_name: ent_specialist_centre
|
| 21 |
+
data_files: data/ear_ent_specialist_centre.csv
|
| 22 |
+
- config_name: district_hospital
|
| 23 |
+
data_files: data/ear_district_hospital.csv
|
| 24 |
+
default: true
|
| 25 |
+
- config_name: rural_health_centre
|
| 26 |
+
data_files: data/ear_rural_health_centre.csv
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
# Hearing Loss & Ear Disease Dataset
|
| 30 |
+
|
| 31 |
+
## Abstract
|
| 32 |
+
|
| 33 |
+
This dataset provides **30,000 simulated ear disease and hearing loss records** (10,000 per scenario) from sub-Saharan Africa. Each record contains 45+ variables including ear condition, hearing assessment, risk factors, treatment, and outcomes. Three settings: ENT specialist centre (audiometry + hearing aids), district hospital (basic care), and rural health centre (minimal services).
|
| 34 |
+
|
| 35 |
+
## 1. Introduction
|
| 36 |
+
|
| 37 |
+
Up to 88% of hearing loss cases are preventable (WHO AFRO). CSOM is the most common ear pathology in SSA, with >56% of school children failing ear examinations. There are fewer than 1 ENT specialist per million population in most SSA countries. Audiometry is rarely available outside tertiary centres, and hearing aids reach <1% of those who need them. Untreated hearing loss in children leads to speech delay and poor school performance.
|
| 38 |
+
|
| 39 |
+
**This dataset is entirely simulated. It must not be used for clinical decision-making.**
|
| 40 |
+
|
| 41 |
+
## 2. Methodology
|
| 42 |
+
|
| 43 |
+
### 2.1 Parameterization
|
| 44 |
+
|
| 45 |
+
| Parameter | Value | Source |
|
| 46 |
+
| --- | --- | --- |
|
| 47 |
+
| Preventable hearing loss | Up to 88% | WHO AFRO |
|
| 48 |
+
| CSOM prevalence | ~27% of cases | PMC 2017 |
|
| 49 |
+
| School ear exam fail rate | 56.6% | ScienceDirect 2019 |
|
| 50 |
+
| ENT specialists per million | <1 | WHO AFRO |
|
| 51 |
+
| Hearing aid coverage | <1% | WHO |
|
| 52 |
+
|
| 53 |
+
### 2.2 Scenario Design
|
| 54 |
+
|
| 55 |
+
| Scenario | Audiometry | Hearing Aids | Surgery | ENT |
|
| 56 |
+
| --- | --- | --- | --- | --- |
|
| 57 |
+
| ENT specialist | Yes | Yes | Yes | Yes |
|
| 58 |
+
| District hospital | No | No | No | No |
|
| 59 |
+
| Rural HC | No | No | No | No |
|
| 60 |
+
|
| 61 |
+
## 3. Schema
|
| 62 |
+
|
| 63 |
+
| Column | Type | Description |
|
| 64 |
+
| --- | --- | --- |
|
| 65 |
+
| id | int | Unique identifier |
|
| 66 |
+
| age | int | Patient age |
|
| 67 |
+
| ear_condition | categorical | csom / aom / ome / wax / foreign_body / noise / presbycusis / congenital / ototoxicity |
|
| 68 |
+
| hearing_loss_severity | categorical | normal / mild / moderate / severe / profound |
|
| 69 |
+
| hearing_loss_type | categorical | conductive / sensorineural / mixed |
|
| 70 |
+
| audiometry_done | binary | Audiometry performed |
|
| 71 |
+
| hearing_aid_fitted | binary | Hearing aid fitted |
|
| 72 |
+
| surgery_performed | binary | Ear surgery |
|
| 73 |
+
| speech_development_affected | binary | Speech delay (children) |
|
| 74 |
+
| school_performance_affected | binary | School impact (children) |
|
| 75 |
+
| complication | binary | Complication occurred |
|
| 76 |
+
|
| 77 |
+
## 4. Validation
|
| 78 |
+
|
| 79 |
+
<p align="center">
|
| 80 |
+
<img src="validation_report.png" alt="Validation Report" width="100%">
|
| 81 |
+
</p>
|
| 82 |
+
|
| 83 |
+
Key validation checks:
|
| 84 |
+
|
| 85 |
+
- **CSOM**: #1 ear condition ✓
|
| 86 |
+
- **Audiometry**: 60% ENT centre → 0% elsewhere ✓
|
| 87 |
+
- **Hearing aids**: 7% specialist → 0% elsewhere ✓
|
| 88 |
+
- **Speech delay**: ~60% in children with moderate+ loss ✓
|
| 89 |
+
- **ENT referral completion**: ~20% ✓
|
| 90 |
+
|
| 91 |
+
## 5. Usage
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
from datasets import load_dataset
|
| 95 |
+
dataset = load_dataset("electricsheepafrica/hearing-loss-ear-disease", "district_hospital")
|
| 96 |
+
df = dataset["train"].to_pandas()
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
## 6. Limitations
|
| 100 |
+
|
| 101 |
+
- **Simulated**: Not from real ENT registries.
|
| 102 |
+
- **No audiogram data**: No frequency-specific thresholds.
|
| 103 |
+
- **No imaging**: No CT temporal bone.
|
| 104 |
+
- **Simplified**: No detailed surgical outcomes.
|
| 105 |
+
|
| 106 |
+
## 7. References
|
| 107 |
+
|
| 108 |
+
1. PMC (2017). CSOM prevalence school children Malawi.
|
| 109 |
+
2. Cambridge (2024). Global burden hearing impairment.
|
| 110 |
+
3. Frontiers (2024). Global burden otitis media.
|
| 111 |
+
4. WHO AFRO. Ear health factsheet.
|
| 112 |
+
5. ScienceDirect (2019). School ear exam prevalence.
|
| 113 |
+
|
| 114 |
+
## Citation
|
| 115 |
+
|
| 116 |
+
```bibtex
|
| 117 |
+
@dataset{esa_hearing_ear_2025,
|
| 118 |
+
title={Hearing Loss and Ear Disease Dataset},
|
| 119 |
+
author={Electric Sheep Africa},
|
| 120 |
+
year={2025},
|
| 121 |
+
publisher={Hugging Face},
|
| 122 |
+
url={https://huggingface.co/datasets/electricsheepafrica/hearing-loss-ear-disease}
|
| 123 |
+
}
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
## License
|
| 127 |
+
|
| 128 |
+
[CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
|
data/ear_district_hospital.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/ear_ent_specialist_centre.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/ear_rural_health_centre.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Literature-Informed Hearing Loss & Ear Disease Dataset
|
| 4 |
+
=======================================================
|
| 5 |
+
|
| 6 |
+
Generates realistic synthetic records of ear disease and hearing
|
| 7 |
+
loss patients in sub-Saharan Africa, including otitis media,
|
| 8 |
+
hearing assessment, hearing aids, and outcomes.
|
| 9 |
+
|
| 10 |
+
References (web-searched):
|
| 11 |
+
-----------
|
| 12 |
+
[1] PMC 2017. CSOM prevalence in school-age children
|
| 13 |
+
Malawi. Population-representative sample.
|
| 14 |
+
[2] Cambridge 2024. Global burden hearing impairment.
|
| 15 |
+
Highest incidence otitis media in LMICs.
|
| 16 |
+
[3] Frontiers 2024. Global burden otitis media 204
|
| 17 |
+
countries. SSA disproportionate burden.
|
| 18 |
+
[4] WHO AFRO. Up to 88% of cases preventable.
|
| 19 |
+
<1 ENT per million in most SSA countries.
|
| 20 |
+
[5] ScienceDirect 2019. 56.6% fail rate school ear
|
| 21 |
+
exams. OM with effusion most common.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
import numpy as np
|
| 25 |
+
import pandas as pd
|
| 26 |
+
import argparse
|
| 27 |
+
import os
|
| 28 |
+
|
| 29 |
+
SCENARIOS = {
|
| 30 |
+
'ent_specialist_centre': {
|
| 31 |
+
'description': 'ENT specialist centre with audiometry, '
|
| 32 |
+
'tympanometry, hearing aids, surgery '
|
| 33 |
+
'(e.g., Groote Schuur, LUTH)',
|
| 34 |
+
'audiometry_available': True,
|
| 35 |
+
'hearing_aids_available': True,
|
| 36 |
+
'surgery_available': True,
|
| 37 |
+
'ent_specialist': True,
|
| 38 |
+
},
|
| 39 |
+
'district_hospital': {
|
| 40 |
+
'description': 'District hospital with otoscopy, basic '
|
| 41 |
+
'tuning fork tests, ear syringing, '
|
| 42 |
+
'antibiotics (e.g., district hospitals)',
|
| 43 |
+
'audiometry_available': False,
|
| 44 |
+
'hearing_aids_available': False,
|
| 45 |
+
'surgery_available': False,
|
| 46 |
+
'ent_specialist': False,
|
| 47 |
+
},
|
| 48 |
+
'rural_health_centre': {
|
| 49 |
+
'description': 'Rural health centre, clinical diagnosis '
|
| 50 |
+
'only, no otoscope often, traditional '
|
| 51 |
+
'remedies common (e.g., rural DRC, Niger)',
|
| 52 |
+
'audiometry_available': False,
|
| 53 |
+
'hearing_aids_available': False,
|
| 54 |
+
'surgery_available': False,
|
| 55 |
+
'ent_specialist': False,
|
| 56 |
+
},
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def generate_dataset(n=10000, seed=42, scenario='district_hospital'):
|
| 61 |
+
rng = np.random.default_rng(seed)
|
| 62 |
+
sc = SCENARIOS[scenario]
|
| 63 |
+
|
| 64 |
+
records = []
|
| 65 |
+
|
| 66 |
+
for idx in range(n):
|
| 67 |
+
rec = {'id': idx + 1}
|
| 68 |
+
|
| 69 |
+
# ── 1. Demographics ──
|
| 70 |
+
rec['age'] = max(0, min(90, int(rng.exponential(20) + 2)))
|
| 71 |
+
rec['sex'] = rng.choice(['M', 'F'], p=[0.52, 0.48])
|
| 72 |
+
rec['child'] = 1 if rec['age'] < 15 else 0
|
| 73 |
+
rec['urban'] = 1 if rng.random() < 0.35 else 0
|
| 74 |
+
rec['education'] = rng.choice(
|
| 75 |
+
['none', 'primary', 'secondary', 'tertiary'],
|
| 76 |
+
p=[0.25, 0.35, 0.30, 0.10])
|
| 77 |
+
|
| 78 |
+
# ── 2. Ear condition ──
|
| 79 |
+
rec['ear_condition'] = rng.choice(
|
| 80 |
+
['csom', 'aom', 'ome', 'wax_impaction', 'foreign_body',
|
| 81 |
+
'noise_induced', 'presbycusis', 'congenital', 'ototoxicity'],
|
| 82 |
+
p=[0.25, 0.15, 0.12, 0.10, 0.05,
|
| 83 |
+
0.08, 0.12, 0.05, 0.08])
|
| 84 |
+
if rec['child']:
|
| 85 |
+
rec['ear_condition'] = rng.choice(
|
| 86 |
+
['csom', 'aom', 'ome', 'foreign_body', 'congenital', 'wax_impaction'],
|
| 87 |
+
p=[0.30, 0.25, 0.15, 0.10, 0.10, 0.10])
|
| 88 |
+
elif rec['age'] > 60:
|
| 89 |
+
rec['ear_condition'] = rng.choice(
|
| 90 |
+
['presbycusis', 'csom', 'wax_impaction', 'noise_induced', 'ototoxicity'],
|
| 91 |
+
p=[0.40, 0.20, 0.15, 0.15, 0.10])
|
| 92 |
+
|
| 93 |
+
rec['laterality'] = rng.choice(['unilateral', 'bilateral'],
|
| 94 |
+
p=[0.55, 0.45])
|
| 95 |
+
rec['duration_months'] = max(0, min(240, int(rng.exponential(12))))
|
| 96 |
+
|
| 97 |
+
# ── 3. Risk factors ──
|
| 98 |
+
rec['recurrent_ari'] = 1 if rec['child'] and rng.random() < 0.40 else 0
|
| 99 |
+
rec['malnutrition'] = 1 if rec['child'] and rng.random() < 0.20 else 0
|
| 100 |
+
rec['overcrowding'] = 1 if rng.random() < 0.45 else 0
|
| 101 |
+
rec['noise_exposure'] = 0
|
| 102 |
+
if rec['age'] >= 15:
|
| 103 |
+
rec['noise_exposure'] = 1 if rng.random() < 0.15 else 0
|
| 104 |
+
rec['ototoxic_medication'] = 0
|
| 105 |
+
if rec['ear_condition'] == 'ototoxicity' or rng.random() < 0.05:
|
| 106 |
+
rec['ototoxic_medication'] = 1
|
| 107 |
+
rec['hiv_positive'] = 1 if rng.random() < 0.06 else 0
|
| 108 |
+
rec['traditional_ear_drops'] = 1 if rng.random() < 0.25 else 0
|
| 109 |
+
|
| 110 |
+
# ── 4. Symptoms ──
|
| 111 |
+
rec['ear_discharge'] = 0
|
| 112 |
+
if rec['ear_condition'] in ('csom', 'aom'):
|
| 113 |
+
rec['ear_discharge'] = 1 if rng.random() < 0.80 else 0
|
| 114 |
+
rec['ear_pain'] = 0
|
| 115 |
+
if rec['ear_condition'] in ('aom', 'foreign_body'):
|
| 116 |
+
rec['ear_pain'] = 1 if rng.random() < 0.85 else 0
|
| 117 |
+
rec['hearing_difficulty'] = 1 if rng.random() < 0.70 else 0
|
| 118 |
+
rec['tinnitus'] = 1 if rng.random() < 0.25 else 0
|
| 119 |
+
rec['vertigo'] = 1 if rng.random() < 0.10 else 0
|
| 120 |
+
|
| 121 |
+
# ── 5. Assessment ──
|
| 122 |
+
rec['otoscopy_done'] = 1 if rng.random() < (0.90 if sc['ent_specialist'] else 0.50) else 0
|
| 123 |
+
rec['tympanic_membrane_perforation'] = 0
|
| 124 |
+
if rec['ear_condition'] == 'csom':
|
| 125 |
+
rec['tympanic_membrane_perforation'] = 1 if rng.random() < 0.85 else 0
|
| 126 |
+
|
| 127 |
+
rec['audiometry_done'] = 0
|
| 128 |
+
if sc['audiometry_available']:
|
| 129 |
+
rec['audiometry_done'] = 1 if rng.random() < 0.60 else 0
|
| 130 |
+
|
| 131 |
+
rec['hearing_loss_severity'] = 'normal'
|
| 132 |
+
if rec['hearing_difficulty']:
|
| 133 |
+
rec['hearing_loss_severity'] = rng.choice(
|
| 134 |
+
['mild', 'moderate', 'severe', 'profound'],
|
| 135 |
+
p=[0.35, 0.30, 0.20, 0.15])
|
| 136 |
+
|
| 137 |
+
rec['hearing_loss_type'] = 'none'
|
| 138 |
+
if rec['hearing_loss_severity'] != 'normal':
|
| 139 |
+
if rec['ear_condition'] in ('csom', 'aom', 'ome', 'wax_impaction'):
|
| 140 |
+
rec['hearing_loss_type'] = 'conductive'
|
| 141 |
+
elif rec['ear_condition'] in ('noise_induced', 'presbycusis', 'ototoxicity', 'congenital'):
|
| 142 |
+
rec['hearing_loss_type'] = 'sensorineural'
|
| 143 |
+
else:
|
| 144 |
+
rec['hearing_loss_type'] = rng.choice(
|
| 145 |
+
['conductive', 'sensorineural', 'mixed'], p=[0.40, 0.40, 0.20])
|
| 146 |
+
|
| 147 |
+
# ── 6. Treatment ──
|
| 148 |
+
rec['antibiotics_given'] = 0
|
| 149 |
+
if rec['ear_condition'] in ('csom', 'aom'):
|
| 150 |
+
rec['antibiotics_given'] = 1 if rng.random() < 0.70 else 0
|
| 151 |
+
rec['ear_drops_given'] = 0
|
| 152 |
+
if rec['ear_condition'] in ('csom', 'aom'):
|
| 153 |
+
rec['ear_drops_given'] = 1 if rng.random() < 0.60 else 0
|
| 154 |
+
rec['ear_syringing'] = 0
|
| 155 |
+
if rec['ear_condition'] == 'wax_impaction':
|
| 156 |
+
rec['ear_syringing'] = 1 if rng.random() < 0.60 else 0
|
| 157 |
+
rec['foreign_body_removal'] = 0
|
| 158 |
+
if rec['ear_condition'] == 'foreign_body':
|
| 159 |
+
rec['foreign_body_removal'] = 1 if rng.random() < 0.70 else 0
|
| 160 |
+
|
| 161 |
+
rec['surgery_performed'] = 0
|
| 162 |
+
if sc['surgery_available'] and rec['ear_condition'] == 'csom' and rec['tympanic_membrane_perforation']:
|
| 163 |
+
rec['surgery_performed'] = 1 if rng.random() < 0.20 else 0
|
| 164 |
+
rec['surgery_type'] = 'none'
|
| 165 |
+
if rec['surgery_performed']:
|
| 166 |
+
rec['surgery_type'] = rng.choice(
|
| 167 |
+
['tympanoplasty', 'mastoidectomy', 'myringoplasty'],
|
| 168 |
+
p=[0.45, 0.30, 0.25])
|
| 169 |
+
|
| 170 |
+
rec['hearing_aid_fitted'] = 0
|
| 171 |
+
if sc['hearing_aids_available'] and rec['hearing_loss_severity'] in ('moderate', 'severe', 'profound'):
|
| 172 |
+
rec['hearing_aid_fitted'] = 1 if rng.random() < 0.15 else 0
|
| 173 |
+
|
| 174 |
+
rec['referred_ent'] = 0
|
| 175 |
+
if not sc['ent_specialist'] and rec['ear_condition'] in ('csom', 'congenital'):
|
| 176 |
+
rec['referred_ent'] = 1 if rng.random() < 0.30 else 0
|
| 177 |
+
rec['referral_completed'] = 0
|
| 178 |
+
if rec['referred_ent']:
|
| 179 |
+
rec['referral_completed'] = 1 if rng.random() < 0.20 else 0
|
| 180 |
+
|
| 181 |
+
# ── 7. Outcome ──
|
| 182 |
+
rec['hearing_improved'] = 0
|
| 183 |
+
if rec['ear_condition'] in ('wax_impaction', 'foreign_body', 'ome') and (
|
| 184 |
+
rec['ear_syringing'] or rec['foreign_body_removal']):
|
| 185 |
+
rec['hearing_improved'] = 1 if rng.random() < 0.80 else 0
|
| 186 |
+
elif rec['surgery_performed']:
|
| 187 |
+
rec['hearing_improved'] = 1 if rng.random() < 0.60 else 0
|
| 188 |
+
elif rec['hearing_aid_fitted']:
|
| 189 |
+
rec['hearing_improved'] = 1 if rng.random() < 0.70 else 0
|
| 190 |
+
|
| 191 |
+
rec['speech_development_affected'] = 0
|
| 192 |
+
if rec['child'] and rec['hearing_loss_severity'] in ('moderate', 'severe', 'profound'):
|
| 193 |
+
rec['speech_development_affected'] = 1 if rng.random() < 0.60 else 0
|
| 194 |
+
|
| 195 |
+
rec['school_performance_affected'] = 0
|
| 196 |
+
if rec['child'] and rec['hearing_difficulty']:
|
| 197 |
+
rec['school_performance_affected'] = 1 if rng.random() < 0.40 else 0
|
| 198 |
+
|
| 199 |
+
rec['complication'] = 0
|
| 200 |
+
if rec['ear_condition'] == 'csom' and not rec['antibiotics_given']:
|
| 201 |
+
rec['complication'] = 1 if rng.random() < 0.10 else 0
|
| 202 |
+
rec['complication_type'] = 'none'
|
| 203 |
+
if rec['complication']:
|
| 204 |
+
rec['complication_type'] = rng.choice(
|
| 205 |
+
['mastoiditis', 'meningitis', 'brain_abscess', 'cholesteatoma'],
|
| 206 |
+
p=[0.40, 0.15, 0.10, 0.35])
|
| 207 |
+
|
| 208 |
+
records.append(rec)
|
| 209 |
+
|
| 210 |
+
df = pd.DataFrame(records)
|
| 211 |
+
|
| 212 |
+
print(f"\n{'='*65}")
|
| 213 |
+
print(f"Hearing/Ear — {scenario} (n={n}, seed={seed})")
|
| 214 |
+
print(f"{'='*65}")
|
| 215 |
+
print(f"\n CSOM: {(df['ear_condition']=='csom').mean()*100:.1f}%")
|
| 216 |
+
print(f" Hearing difficulty: {df['hearing_difficulty'].mean()*100:.1f}%")
|
| 217 |
+
print(f" Audiometry done: {df['audiometry_done'].mean()*100:.1f}%")
|
| 218 |
+
print(f" Hearing aid: {df['hearing_aid_fitted'].mean()*100:.1f}%")
|
| 219 |
+
print(f" ENT referral: {df['referred_ent'].mean()*100:.1f}%")
|
| 220 |
+
|
| 221 |
+
return df
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
if __name__ == '__main__':
|
| 225 |
+
parser = argparse.ArgumentParser(
|
| 226 |
+
description='Generate hearing loss/ear disease dataset')
|
| 227 |
+
parser.add_argument('--scenario', type=str, default='district_hospital',
|
| 228 |
+
choices=list(SCENARIOS.keys()))
|
| 229 |
+
parser.add_argument('--n', type=int, default=10000)
|
| 230 |
+
parser.add_argument('--seed', type=int, default=42)
|
| 231 |
+
parser.add_argument('--output', type=str, default=None)
|
| 232 |
+
parser.add_argument('--all-scenarios', action='store_true')
|
| 233 |
+
args = parser.parse_args()
|
| 234 |
+
|
| 235 |
+
os.makedirs('data', exist_ok=True)
|
| 236 |
+
|
| 237 |
+
if args.all_scenarios:
|
| 238 |
+
for sc_name in SCENARIOS:
|
| 239 |
+
df = generate_dataset(n=args.n, seed=args.seed, scenario=sc_name)
|
| 240 |
+
out = os.path.join('data', f'ear_{sc_name}.csv')
|
| 241 |
+
df.to_csv(out, index=False)
|
| 242 |
+
print(f" -> Saved to {out}\n")
|
| 243 |
+
else:
|
| 244 |
+
df = generate_dataset(n=args.n, seed=args.seed, scenario=args.scenario)
|
| 245 |
+
out = args.output or os.path.join('data', f'ear_{args.scenario}.csv')
|
| 246 |
+
df.to_csv(out, index=False)
|
| 247 |
+
print(f" -> Saved to {out}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy>=1.24
|
| 2 |
+
pandas>=2.0
|
| 3 |
+
matplotlib>=3.7
|
validate_dataset.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Validation & Diagnostic Visualization for Hearing Loss/Ear Disease Dataset."""
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import numpy as np
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
SCENARIOS = ['ent_specialist_centre', 'district_hospital', 'rural_health_centre']
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def load_scenarios(data_dir='data'):
|
| 13 |
+
dfs = {}
|
| 14 |
+
for sc in SCENARIOS:
|
| 15 |
+
path = os.path.join(data_dir, f'ear_{sc}.csv')
|
| 16 |
+
if os.path.exists(path):
|
| 17 |
+
dfs[sc] = pd.read_csv(path)
|
| 18 |
+
return dfs
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def make_report(dfs, output='validation_report.png'):
|
| 22 |
+
fig, axes = plt.subplots(4, 2, figsize=(16, 22))
|
| 23 |
+
fig.suptitle('Hearing Loss & Ear Disease — Validation Report',
|
| 24 |
+
fontsize=16, fontweight='bold', y=0.98)
|
| 25 |
+
df = dfs.get('district_hospital', list(dfs.values())[0])
|
| 26 |
+
colors = ['#2ecc71', '#f39c12', '#e74c3c']
|
| 27 |
+
|
| 28 |
+
ax = axes[0, 0]
|
| 29 |
+
conds = df['ear_condition'].value_counts()
|
| 30 |
+
c_colors = ['#e74c3c', '#f39c12', '#3498db', '#9b59b6', '#2ecc71',
|
| 31 |
+
'#e67e22', '#1abc9c', '#95a5a6', '#c0392b']
|
| 32 |
+
ax.barh(range(len(conds)), conds.values, color=c_colors[:len(conds)], alpha=0.8)
|
| 33 |
+
ax.set_yticks(range(len(conds)))
|
| 34 |
+
ax.set_yticklabels([s.replace('_', ' ').title() for s in conds.index], fontsize=7)
|
| 35 |
+
ax.set_xlabel('Count')
|
| 36 |
+
ax.set_title('Ear Conditions (CSOM #1)')
|
| 37 |
+
|
| 38 |
+
ax = axes[0, 1]
|
| 39 |
+
x = np.arange(len(SCENARIOS))
|
| 40 |
+
audio = [dfs[sc]['audiometry_done'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 41 |
+
ha = [dfs[sc]['hearing_aid_fitted'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 42 |
+
w = 0.3
|
| 43 |
+
ax.bar(x - w/2, audio, w, label='Audiometry', color='#3498db', alpha=0.8)
|
| 44 |
+
ax.bar(x + w/2, ha, w, label='Hearing Aid', color='#2ecc71', alpha=0.8)
|
| 45 |
+
ax.set_xticks(x)
|
| 46 |
+
ax.set_xticklabels(['ENT Centre', 'District', 'Rural'], fontsize=9)
|
| 47 |
+
ax.set_ylabel('Rate (%)')
|
| 48 |
+
ax.set_title('Audiometry & Hearing Aid Access')
|
| 49 |
+
ax.legend(fontsize=8)
|
| 50 |
+
|
| 51 |
+
ax = axes[1, 0]
|
| 52 |
+
sev = df['hearing_loss_severity'].value_counts()
|
| 53 |
+
s_order = ['normal', 'mild', 'moderate', 'severe', 'profound']
|
| 54 |
+
vals = [sev.get(s, 0) for s in s_order]
|
| 55 |
+
ax.bar(range(5), vals, color=['#2ecc71', '#f1c40f', '#f39c12', '#e74c3c', '#8e44ad'], alpha=0.8)
|
| 56 |
+
ax.set_xticks(range(5))
|
| 57 |
+
ax.set_xticklabels(s_order, fontsize=9)
|
| 58 |
+
ax.set_ylabel('Count')
|
| 59 |
+
ax.set_title('Hearing Loss Severity')
|
| 60 |
+
|
| 61 |
+
ax = axes[1, 1]
|
| 62 |
+
hl_type = df[df['hearing_loss_type'] != 'none']['hearing_loss_type'].value_counts()
|
| 63 |
+
if len(hl_type) > 0:
|
| 64 |
+
ax.pie(hl_type.values,
|
| 65 |
+
labels=[s.title() for s in hl_type.index],
|
| 66 |
+
autopct='%1.0f%%', colors=['#3498db', '#e74c3c', '#f39c12'],
|
| 67 |
+
startangle=90, textprops={'fontsize': 10})
|
| 68 |
+
ax.set_title('Hearing Loss Type')
|
| 69 |
+
|
| 70 |
+
ax = axes[2, 0]
|
| 71 |
+
children = df[df['child'] == 1]
|
| 72 |
+
if len(children) > 0:
|
| 73 |
+
impacts = ['speech_development_affected', 'school_performance_affected']
|
| 74 |
+
i_labels = ['Speech Affected', 'School Affected']
|
| 75 |
+
vals = [children[i].mean()*100 for i in impacts]
|
| 76 |
+
ax.bar(range(2), vals, color=['#e74c3c', '#f39c12'], alpha=0.8)
|
| 77 |
+
ax.set_xticks(range(2))
|
| 78 |
+
ax.set_xticklabels(i_labels, fontsize=9)
|
| 79 |
+
for i, v in enumerate(vals):
|
| 80 |
+
ax.text(i, v + 1, f'{v:.0f}%', ha='center', fontsize=10)
|
| 81 |
+
ax.set_ylabel('Rate (%)')
|
| 82 |
+
ax.set_title('Impact on Children')
|
| 83 |
+
|
| 84 |
+
ax = axes[2, 1]
|
| 85 |
+
risks = ['recurrent_ari', 'malnutrition', 'overcrowding',
|
| 86 |
+
'noise_exposure', 'traditional_ear_drops']
|
| 87 |
+
r_labels = ['Recurrent ARI', 'Malnutrition', 'Overcrowding',
|
| 88 |
+
'Noise', 'Trad. Drops']
|
| 89 |
+
vals = [df[r].mean()*100 for r in risks]
|
| 90 |
+
ax.barh(range(5), vals, color='#3498db', alpha=0.7)
|
| 91 |
+
ax.set_yticks(range(5))
|
| 92 |
+
ax.set_yticklabels(r_labels, fontsize=9)
|
| 93 |
+
ax.set_xlabel('Prevalence (%)')
|
| 94 |
+
ax.set_title('Risk Factors')
|
| 95 |
+
|
| 96 |
+
ax = axes[3, 0]
|
| 97 |
+
tx = ['antibiotics_given', 'ear_drops_given', 'ear_syringing',
|
| 98 |
+
'surgery_performed', 'hearing_aid_fitted']
|
| 99 |
+
t_labels = ['Antibiotics', 'Ear Drops', 'Syringing', 'Surgery', 'Hearing Aid']
|
| 100 |
+
for i, sc_name in enumerate(SCENARIOS):
|
| 101 |
+
if sc_name in dfs:
|
| 102 |
+
d = dfs[sc_name]
|
| 103 |
+
vals = [d[t].mean()*100 for t in tx]
|
| 104 |
+
ax.plot(range(5), vals, 'o-', label=sc_name.replace('_', ' ').title()[:10],
|
| 105 |
+
color=colors[i], linewidth=2, markersize=5)
|
| 106 |
+
ax.set_xticks(range(5))
|
| 107 |
+
ax.set_xticklabels(t_labels, fontsize=7, rotation=15)
|
| 108 |
+
ax.set_ylabel('Rate (%)')
|
| 109 |
+
ax.set_title('Treatment Cascade by Scenario')
|
| 110 |
+
ax.legend(fontsize=7)
|
| 111 |
+
|
| 112 |
+
ax = axes[3, 1]
|
| 113 |
+
ref = [dfs[sc]['referred_ent'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 114 |
+
ref_c = [dfs[sc]['referral_completed'].mean()*100 for sc in SCENARIOS if sc in dfs]
|
| 115 |
+
ax.bar(x - w/2, ref, w, label='Referred ENT', color='#f39c12', alpha=0.8)
|
| 116 |
+
ax.bar(x + w/2, ref_c, w, label='Referral Done', color='#2ecc71', alpha=0.8)
|
| 117 |
+
ax.set_xticks(x)
|
| 118 |
+
ax.set_xticklabels(['ENT Centre', 'District', 'Rural'], fontsize=9)
|
| 119 |
+
ax.set_ylabel('Rate (%)')
|
| 120 |
+
ax.set_title('ENT Referral Gap (~20% completion)')
|
| 121 |
+
ax.legend(fontsize=8)
|
| 122 |
+
|
| 123 |
+
plt.tight_layout(rect=[0, 0, 1, 0.97])
|
| 124 |
+
plt.savefig(output, dpi=150, bbox_inches='tight')
|
| 125 |
+
print(f'Saved validation report to {output}')
|
| 126 |
+
plt.close()
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
if __name__ == '__main__':
|
| 130 |
+
dfs = load_scenarios()
|
| 131 |
+
if dfs:
|
| 132 |
+
make_report(dfs)
|
validation_report.png
ADDED
|
Git LFS Details
|