Datasets:
Upload folder using huggingface_hub
Browse files- README.md +88 -0
- data/poisoning_agricultural.csv +0 -0
- data/poisoning_household.csv +0 -0
- data/poisoning_industrial.csv +0 -0
- generate_dataset.py +197 -0
- requirements.txt +3 -0
- validate_dataset.py +88 -0
- validation_report.png +3 -0
README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-4.0
|
| 3 |
+
task_categories:
|
| 4 |
+
- tabular-classification
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
tags:
|
| 8 |
+
- environmental-health
|
| 9 |
+
- chemical-poisoning
|
| 10 |
+
- toxicology
|
| 11 |
+
- pesticide
|
| 12 |
+
- kerosene
|
| 13 |
+
- synthetic
|
| 14 |
+
- sub-saharan-africa
|
| 15 |
+
pretty_name: Chemical Poisoning & Toxicology (SSA)
|
| 16 |
+
size_categories:
|
| 17 |
+
- 10K<n<100K
|
| 18 |
+
configs:
|
| 19 |
+
- config_name: agricultural_pesticide
|
| 20 |
+
data_files: data/poisoning_agricultural.csv
|
| 21 |
+
default: true
|
| 22 |
+
- config_name: household_chemical_urban
|
| 23 |
+
data_files: data/poisoning_household.csv
|
| 24 |
+
- config_name: industrial_occupational
|
| 25 |
+
data_files: data/poisoning_industrial.csv
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
# Chemical Poisoning & Toxicology in Sub-Saharan Africa
|
| 29 |
+
|
| 30 |
+
## Abstract
|
| 31 |
+
|
| 32 |
+
Synthetic dataset modelling chemical poisoning cases, agents, severity, clinical management, and outcomes across three exposure contexts in SSA. Children in LMICs face 4x higher poisoning mortality. Common agents include organophosphates, kerosene, household chemicals, and street-sold rodenticides. Poison control centres are virtually absent in most SSA countries.
|
| 33 |
+
|
| 34 |
+
### Scenarios
|
| 35 |
+
|
| 36 |
+
- **Agricultural Pesticide**: Rural/peri-urban organophosphate and carbamate poisoning; occupational and accidental child exposure.
|
| 37 |
+
- **Household Chemical Urban**: Kerosene ingestion, bleach, medication overdose, street rat poison in urban informal settings.
|
| 38 |
+
- **Industrial Occupational**: Solvent, heavy metal compound, acid/alkali, gas/fume exposure in workplaces.
|
| 39 |
+
|
| 40 |
+
## Parameterization Evidence
|
| 41 |
+
|
| 42 |
+
| Parameter | Value | Source | Year |
|
| 43 |
+
| --- | --- | --- | --- |
|
| 44 |
+
| Child pesticide mortality in SA; street pesticides | SSA data | BMC Public Health | 2023 |
|
| 45 |
+
| 4x higher poisoning mortality in LMICs children | Burden | Frontiers in Public Health | 2023 |
|
| 46 |
+
| Organophosphate toxicity highest in agricultural LMICs | Mechanism | StatPearls / NCBI | 2024 |
|
| 47 |
+
| Dozens of children died from unregulated pesticides in SA | Incident | Beyond Pesticides | 2024 |
|
| 48 |
+
| ~45,000 poisoning deaths/yr in Africa | Mortality | WHO | 2023 |
|
| 49 |
+
|
| 50 |
+
## Validation
|
| 51 |
+
|
| 52 |
+

|
| 53 |
+
|
| 54 |
+
## Usage
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from datasets import load_dataset
|
| 58 |
+
ds = load_dataset("electricsheepafrica/chemical-poisoning-toxicology", "agricultural_pesticide")
|
| 59 |
+
```
|
| 60 |
+
|
| 61 |
+
## Limitations
|
| 62 |
+
|
| 63 |
+
- Synthetic data; not for clinical decision-making.
|
| 64 |
+
- Does not capture traditional medicine poisoning in detail.
|
| 65 |
+
- Severity distribution simplified from heterogeneous case series.
|
| 66 |
+
|
| 67 |
+
## References
|
| 68 |
+
|
| 69 |
+
1. BMC Public Health. Child/adolescent pesticide poisoning mortality in SA. 2023.
|
| 70 |
+
2. Frontiers in Public Health. Burden of poisoning in children in LMICs. 2023.
|
| 71 |
+
3. StatPearls. Organophosphate Toxicity. 2024.
|
| 72 |
+
4. Beyond Pesticides. Deadly poisoning of children in South Africa. 2024.
|
| 73 |
+
|
| 74 |
+
## Citation
|
| 75 |
+
|
| 76 |
+
```bibtex
|
| 77 |
+
@dataset{electricsheepafrica_chemical_poisoning_toxicology_2025,
|
| 78 |
+
title={Chemical Poisoning and Toxicology in Sub-Saharan Africa},
|
| 79 |
+
author={Electric Sheep Africa},
|
| 80 |
+
year={2025},
|
| 81 |
+
publisher={HuggingFace},
|
| 82 |
+
url={https://huggingface.co/datasets/electricsheepafrica/chemical-poisoning-toxicology}
|
| 83 |
+
}
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## License
|
| 87 |
+
|
| 88 |
+
CC-BY-4.0
|
data/poisoning_agricultural.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/poisoning_household.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/poisoning_industrial.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
generate_dataset.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Generate synthetic chemical poisoning & toxicology dataset for SSA.
|
| 2 |
+
|
| 3 |
+
Research-based parameterization:
|
| 4 |
+
- BMC Public Health (2023): Child/adolescent pesticide poisoning mortality
|
| 5 |
+
in SA; street pesticides (aldicarb, organophosphates) sold illegally.
|
| 6 |
+
- Frontiers (2023): Children poisoning in LMICs - 4x higher mortality;
|
| 7 |
+
medications, pesticides, kerosene, household chemicals.
|
| 8 |
+
- StatPearls: Organophosphate toxicity highest in agricultural developing
|
| 9 |
+
nations with less stringent regulations.
|
| 10 |
+
- Beyond Pesticides (2024): Dozens of children died in SA from
|
| 11 |
+
unregulated pesticide use in communities.
|
| 12 |
+
- WHO: Poisoning causes ~45,000 deaths/yr in Africa.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
from __future__ import annotations
|
| 16 |
+
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
import numpy as np
|
| 20 |
+
import pandas as pd
|
| 21 |
+
|
| 22 |
+
SEED = 42
|
| 23 |
+
N_PER_SCENARIO = 10_000
|
| 24 |
+
|
| 25 |
+
YEAR_RANGE = np.arange(2010, 2025)
|
| 26 |
+
YEAR_WEIGHTS = np.linspace(0.85, 1.3, len(YEAR_RANGE))
|
| 27 |
+
YEAR_WEIGHTS = YEAR_WEIGHTS / YEAR_WEIGHTS.sum()
|
| 28 |
+
|
| 29 |
+
SCENARIOS = {
|
| 30 |
+
"agricultural_pesticide": {
|
| 31 |
+
"setting_probs": {"rural_farm": 0.50, "peri_urban": 0.30, "urban": 0.20},
|
| 32 |
+
"agent_probs": {"organophosphate": 0.35, "carbamate": 0.20, "pyrethroid": 0.15,
|
| 33 |
+
"herbicide": 0.15, "rodenticide": 0.10, "fungicide": 0.05},
|
| 34 |
+
"intent_probs": {"accidental_occupational": 0.40, "accidental_child": 0.20,
|
| 35 |
+
"intentional_self_harm": 0.25, "intentional_other": 0.05, "unknown": 0.10},
|
| 36 |
+
"mortality_rate": 0.08,
|
| 37 |
+
"child_pct": 0.25,
|
| 38 |
+
"ppe_use_pct": 0.12,
|
| 39 |
+
"poison_centre_access": 0.05,
|
| 40 |
+
"antidote_available": 0.30,
|
| 41 |
+
},
|
| 42 |
+
"household_chemical_urban": {
|
| 43 |
+
"setting_probs": {"urban_informal": 0.40, "urban_formal": 0.30, "peri_urban": 0.30},
|
| 44 |
+
"agent_probs": {"kerosene_paraffin": 0.30, "bleach_caustic": 0.20,
|
| 45 |
+
"medication_overdose": 0.20, "rat_poison_street": 0.15,
|
| 46 |
+
"traditional_medicine": 0.10, "other_chemical": 0.05},
|
| 47 |
+
"intent_probs": {"accidental_child": 0.40, "accidental_adult": 0.15,
|
| 48 |
+
"intentional_self_harm": 0.30, "intentional_other": 0.05, "unknown": 0.10},
|
| 49 |
+
"mortality_rate": 0.05,
|
| 50 |
+
"child_pct": 0.45,
|
| 51 |
+
"ppe_use_pct": 0.0,
|
| 52 |
+
"poison_centre_access": 0.10,
|
| 53 |
+
"antidote_available": 0.40,
|
| 54 |
+
},
|
| 55 |
+
"industrial_occupational": {
|
| 56 |
+
"setting_probs": {"industrial": 0.45, "mining": 0.25, "construction": 0.15, "urban": 0.15},
|
| 57 |
+
"agent_probs": {"solvent_hydrocarbon": 0.25, "heavy_metal_compound": 0.20,
|
| 58 |
+
"acid_alkali": 0.15, "gas_fume": 0.20,
|
| 59 |
+
"pesticide_industrial": 0.10, "other_industrial": 0.10},
|
| 60 |
+
"intent_probs": {"accidental_occupational": 0.65, "accidental_other": 0.15,
|
| 61 |
+
"intentional_self_harm": 0.10, "intentional_other": 0.02, "unknown": 0.08},
|
| 62 |
+
"mortality_rate": 0.06,
|
| 63 |
+
"child_pct": 0.05,
|
| 64 |
+
"ppe_use_pct": 0.20,
|
| 65 |
+
"poison_centre_access": 0.08,
|
| 66 |
+
"antidote_available": 0.35,
|
| 67 |
+
},
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
SCENARIO_FILES = {
|
| 71 |
+
"agricultural_pesticide": "poisoning_agricultural.csv",
|
| 72 |
+
"household_chemical_urban": "poisoning_household.csv",
|
| 73 |
+
"industrial_occupational": "poisoning_industrial.csv",
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
ROUTES = {"ingestion": 0.50, "dermal": 0.20, "inhalation": 0.20, "injection": 0.02, "ocular": 0.08}
|
| 77 |
+
SEVERITY = {"mild": 0.35, "moderate": 0.35, "severe": 0.20, "fatal": 0.10}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _choice(rng, prob_map):
|
| 81 |
+
keys = list(prob_map.keys())
|
| 82 |
+
weights = np.array(list(prob_map.values()), dtype=float)
|
| 83 |
+
weights = weights / weights.sum()
|
| 84 |
+
return rng.choice(keys, p=weights)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def _simulate_scenario(name, params, seed):
|
| 88 |
+
rng = np.random.default_rng(seed)
|
| 89 |
+
records = []
|
| 90 |
+
|
| 91 |
+
for idx in range(N_PER_SCENARIO):
|
| 92 |
+
year = int(rng.choice(YEAR_RANGE, p=YEAR_WEIGHTS))
|
| 93 |
+
setting = _choice(rng, params["setting_probs"])
|
| 94 |
+
is_child = int(rng.random() < params["child_pct"])
|
| 95 |
+
age = int(np.clip(rng.normal(3, 1.5) if is_child else rng.normal(32, 12), 0, 70))
|
| 96 |
+
sex = rng.choice(["male", "female"], p=[0.55, 0.45])
|
| 97 |
+
|
| 98 |
+
agent = _choice(rng, params["agent_probs"])
|
| 99 |
+
intent = _choice(rng, params["intent_probs"])
|
| 100 |
+
route = _choice(rng, ROUTES)
|
| 101 |
+
|
| 102 |
+
time_to_presentation_hrs = float(np.clip(rng.lognormal(np.log(3), 0.8), 0.5, 72))
|
| 103 |
+
delayed_presentation = int(time_to_presentation_hrs > 6)
|
| 104 |
+
|
| 105 |
+
severity = _choice(rng, SEVERITY)
|
| 106 |
+
if intent == "intentional_self_harm":
|
| 107 |
+
severity = rng.choice(["moderate", "severe", "fatal"], p=[0.30, 0.45, 0.25])
|
| 108 |
+
|
| 109 |
+
# Clinical features
|
| 110 |
+
gi_symptoms = int(route == "ingestion" and rng.random() < 0.70)
|
| 111 |
+
respiratory_distress = int(route == "inhalation" and rng.random() < 0.50)
|
| 112 |
+
cholinergic_crisis = int(agent in ("organophosphate", "carbamate") and rng.random() < 0.45)
|
| 113 |
+
seizures = int(severity in ("severe", "fatal") and rng.random() < 0.15)
|
| 114 |
+
altered_consciousness = int(severity in ("severe", "fatal") and rng.random() < 0.30)
|
| 115 |
+
chemical_burn = int(agent in ("acid_alkali", "bleach_caustic") and rng.random() < 0.40)
|
| 116 |
+
aspiration_pneumonia = int(agent == "kerosene_paraffin" and rng.random() < 0.25)
|
| 117 |
+
|
| 118 |
+
# Management
|
| 119 |
+
ppe_use = int(rng.random() < params["ppe_use_pct"])
|
| 120 |
+
decontamination = int(rng.random() < 0.40)
|
| 121 |
+
activated_charcoal = int(route == "ingestion" and time_to_presentation_hrs < 2 and rng.random() < 0.30)
|
| 122 |
+
antidote_available = int(rng.random() < params["antidote_available"])
|
| 123 |
+
antidote_given = int(antidote_available and severity in ("moderate", "severe", "fatal") and rng.random() < 0.70)
|
| 124 |
+
atropine_given = int(cholinergic_crisis and rng.random() < 0.60)
|
| 125 |
+
icu_admission = int(severity in ("severe", "fatal") and rng.random() < 0.40)
|
| 126 |
+
ventilator = int(icu_admission and rng.random() < 0.30)
|
| 127 |
+
|
| 128 |
+
poison_centre_consulted = int(rng.random() < params["poison_centre_access"])
|
| 129 |
+
referred_higher = int(severity in ("severe", "fatal") and rng.random() < 0.50)
|
| 130 |
+
|
| 131 |
+
# Outcomes
|
| 132 |
+
died = int(severity == "fatal" and rng.random() < params["mortality_rate"] * 10)
|
| 133 |
+
sequelae = int(severity in ("severe", "fatal") and not died and rng.random() < 0.15)
|
| 134 |
+
hospital_days = int(np.clip(
|
| 135 |
+
rng.poisson(1 if severity == "mild" else 3 if severity == "moderate" else 7), 0, 30))
|
| 136 |
+
|
| 137 |
+
# Prevention
|
| 138 |
+
safe_storage = int(rng.random() < 0.20)
|
| 139 |
+
child_proof_container = int(is_child and rng.random() < 0.05)
|
| 140 |
+
labelled_container = int(rng.random() < 0.30)
|
| 141 |
+
pesticide_regulation = int(rng.random() < 0.15)
|
| 142 |
+
|
| 143 |
+
record = {
|
| 144 |
+
"record_id": f"{name[:3].upper()}-{idx:05d}",
|
| 145 |
+
"scenario": name,
|
| 146 |
+
"year": year,
|
| 147 |
+
"setting": setting,
|
| 148 |
+
"age": age,
|
| 149 |
+
"sex": sex,
|
| 150 |
+
"is_child": is_child,
|
| 151 |
+
"agent": agent,
|
| 152 |
+
"intent": intent,
|
| 153 |
+
"route": route,
|
| 154 |
+
"time_to_presentation_hrs": round(time_to_presentation_hrs, 1),
|
| 155 |
+
"delayed_presentation": delayed_presentation,
|
| 156 |
+
"severity": severity,
|
| 157 |
+
"gi_symptoms": gi_symptoms,
|
| 158 |
+
"respiratory_distress": respiratory_distress,
|
| 159 |
+
"cholinergic_crisis": cholinergic_crisis,
|
| 160 |
+
"seizures": seizures,
|
| 161 |
+
"altered_consciousness": altered_consciousness,
|
| 162 |
+
"chemical_burn": chemical_burn,
|
| 163 |
+
"aspiration_pneumonia": aspiration_pneumonia,
|
| 164 |
+
"ppe_use": ppe_use,
|
| 165 |
+
"decontamination": decontamination,
|
| 166 |
+
"activated_charcoal": activated_charcoal,
|
| 167 |
+
"antidote_available": antidote_available,
|
| 168 |
+
"antidote_given": antidote_given,
|
| 169 |
+
"atropine_given": atropine_given,
|
| 170 |
+
"icu_admission": icu_admission,
|
| 171 |
+
"ventilator": ventilator,
|
| 172 |
+
"poison_centre_consulted": poison_centre_consulted,
|
| 173 |
+
"referred_higher": referred_higher,
|
| 174 |
+
"died": died,
|
| 175 |
+
"sequelae": sequelae,
|
| 176 |
+
"hospital_days": hospital_days,
|
| 177 |
+
"safe_storage": safe_storage,
|
| 178 |
+
"child_proof_container": child_proof_container,
|
| 179 |
+
"labelled_container": labelled_container,
|
| 180 |
+
"pesticide_regulation": pesticide_regulation,
|
| 181 |
+
}
|
| 182 |
+
records.append(record)
|
| 183 |
+
|
| 184 |
+
return pd.DataFrame(records)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def main():
|
| 188 |
+
output_dir = Path("data")
|
| 189 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 190 |
+
for idx, (name, params) in enumerate(SCENARIOS.items()):
|
| 191 |
+
df = _simulate_scenario(name, params, SEED + idx * 211)
|
| 192 |
+
df.to_csv(output_dir / SCENARIO_FILES[name], index=False)
|
| 193 |
+
print(f"Saved {name} -> {SCENARIO_FILES[name]}")
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
if __name__ == "__main__":
|
| 197 |
+
main()
|
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,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Validate synthetic chemical poisoning & toxicology dataset."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import matplotlib.pyplot as plt
|
| 8 |
+
import pandas as pd
|
| 9 |
+
|
| 10 |
+
SCENARIO_FILES = {
|
| 11 |
+
"agricultural_pesticide": "poisoning_agricultural.csv",
|
| 12 |
+
"household_chemical_urban": "poisoning_household.csv",
|
| 13 |
+
"industrial_occupational": "poisoning_industrial.csv",
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
COLORS = {"agricultural_pesticide": "#e6550d", "household_chemical_urban": "#756bb1", "industrial_occupational": "#31a354"}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def load_data() -> pd.DataFrame:
|
| 20 |
+
frames = []
|
| 21 |
+
for scenario, filename in SCENARIO_FILES.items():
|
| 22 |
+
df = pd.read_csv(Path("data") / filename)
|
| 23 |
+
frames.append(df)
|
| 24 |
+
return pd.concat(frames, ignore_index=True)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def plot_validation(df: pd.DataFrame, output_path: Path) -> None:
|
| 28 |
+
fig, axes = plt.subplots(4, 2, figsize=(14, 16))
|
| 29 |
+
axes = axes.flatten()
|
| 30 |
+
|
| 31 |
+
ag = df.groupby(["scenario", "agent"]).size().groupby(level=0).apply(lambda s: s / s.sum())
|
| 32 |
+
ag.unstack().plot(kind="bar", stacked=True, ax=axes[0])
|
| 33 |
+
axes[0].set_title("Poisoning Agent Distribution")
|
| 34 |
+
axes[0].legend(fontsize=4)
|
| 35 |
+
|
| 36 |
+
intent = df.groupby(["scenario", "intent"]).size().groupby(level=0).apply(lambda s: s / s.sum())
|
| 37 |
+
intent.unstack().plot(kind="bar", stacked=True, ax=axes[1])
|
| 38 |
+
axes[1].set_title("Intent Distribution")
|
| 39 |
+
axes[1].legend(fontsize=5)
|
| 40 |
+
|
| 41 |
+
sev = df.groupby(["scenario", "severity"]).size().groupby(level=0).apply(lambda s: s / s.sum())
|
| 42 |
+
sev.unstack().plot(kind="bar", stacked=True, ax=axes[2])
|
| 43 |
+
axes[2].set_title("Severity Distribution")
|
| 44 |
+
axes[2].legend(fontsize=7)
|
| 45 |
+
|
| 46 |
+
clin_cols = ["gi_symptoms", "cholinergic_crisis", "seizures", "altered_consciousness", "aspiration_pneumonia"]
|
| 47 |
+
clin = df.groupby("scenario")[clin_cols].mean() * 100
|
| 48 |
+
clin.plot(kind="bar", ax=axes[3])
|
| 49 |
+
axes[3].set_title("Clinical Features (%)")
|
| 50 |
+
axes[3].legend(fontsize=5)
|
| 51 |
+
|
| 52 |
+
mgmt_cols = ["decontamination", "antidote_given", "atropine_given", "icu_admission", "ventilator"]
|
| 53 |
+
mgmt = df.groupby("scenario")[mgmt_cols].mean() * 100
|
| 54 |
+
mgmt.plot(kind="bar", ax=axes[4])
|
| 55 |
+
axes[4].set_title("Management (%)")
|
| 56 |
+
axes[4].legend(fontsize=6)
|
| 57 |
+
|
| 58 |
+
out_cols = ["died", "sequelae"]
|
| 59 |
+
out = df.groupby("scenario")[out_cols].mean() * 100
|
| 60 |
+
out.plot(kind="bar", ax=axes[5])
|
| 61 |
+
axes[5].set_title("Outcomes: Death & Sequelae (%)")
|
| 62 |
+
axes[5].legend(fontsize=7)
|
| 63 |
+
|
| 64 |
+
prev_cols = ["safe_storage", "labelled_container", "poison_centre_consulted", "pesticide_regulation"]
|
| 65 |
+
prev = df.groupby("scenario")[prev_cols].mean() * 100
|
| 66 |
+
prev.plot(kind="bar", ax=axes[6])
|
| 67 |
+
axes[6].set_title("Prevention & Access (%)")
|
| 68 |
+
axes[6].legend(fontsize=6)
|
| 69 |
+
|
| 70 |
+
for s in SCENARIO_FILES:
|
| 71 |
+
subset = df[df["scenario"] == s]
|
| 72 |
+
axes[7].hist(subset["time_to_presentation_hrs"], bins=30, alpha=0.5, color=COLORS[s], label=s, range=(0, 30))
|
| 73 |
+
axes[7].set_title("Time to Presentation (hours)")
|
| 74 |
+
axes[7].legend(fontsize=7)
|
| 75 |
+
|
| 76 |
+
plt.tight_layout()
|
| 77 |
+
fig.savefig(output_path, dpi=200)
|
| 78 |
+
plt.close(fig)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def main() -> None:
|
| 82 |
+
df = load_data()
|
| 83 |
+
plot_validation(df, Path("validation_report.png"))
|
| 84 |
+
print("Saved validation_report.png")
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
if __name__ == "__main__":
|
| 88 |
+
main()
|
validation_report.png
ADDED
|
Git LFS Details
|