Kossisoroyce commited on
Commit
b734baa
·
verified ·
1 Parent(s): 9176fdf

Add dataset files

Browse files
README.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ task_categories:
4
+ - tabular-classification
5
+ - tabular-regression
6
+ language:
7
+ - en
8
+ tags:
9
+ - healthcare
10
+ - medicine-quality
11
+ - QC-laboratory
12
+ - ISO-17025
13
+ - WHO-prequalification
14
+ - HPLC
15
+ - proficiency-testing
16
+ - sub-saharan-africa
17
+ - lmic
18
+ pretty_name: "Medicine Quality Control Laboratories (Equipment, Staff, Proficiency, Budget)"
19
+ size_categories:
20
+ - 10K<n<100K
21
+ configs:
22
+ - config_name: who_prequalified_lab
23
+ data_files: data/qc_lab_who_prequalified_lab.csv
24
+ - config_name: national_reference_lab
25
+ data_files: data/qc_lab_national_reference_lab.csv
26
+ default: true
27
+ - config_name: district_basic_lab
28
+ data_files: data/qc_lab_district_basic_lab.csv
29
+ ---
30
+
31
+ # Medicine Quality Control Laboratories Dataset
32
+
33
+ ## Abstract
34
+
35
+ **30,000 simulated QC laboratory assessments** (10,000 per scenario) across three laboratory tiers in sub-Saharan Africa. Variables include staff, equipment functionality, testing volume, turnaround time, proficiency testing, budget, reagent stockouts, and SF detection rates. Three scenarios: WHO-prequalified lab (20 staff, 92% equipment functional), national reference (8 staff, 65%), district basic (2 staff, 30%).
36
+
37
+ **This dataset is entirely simulated. It must not be used for laboratory accreditation or regulatory decisions.**
38
+
39
+ ## Validation
40
+
41
+ <p align="center">
42
+ <img src="validation_report.png" alt="Validation Report" width="100%">
43
+ </p>
44
+
45
+ ## Usage
46
+
47
+ ```python
48
+ from datasets import load_dataset
49
+ dataset = load_dataset("electricsheepafrica/medicine-quality-control-labs", "national_reference_lab")
50
+ df = dataset["train"].to_pandas()
51
+ print(df[['staff_analysts', 'equipment_functional_pct', 'samples_tested_per_year']].describe())
52
+ ```
53
+
54
+ ## References
55
+
56
+ 1. WHO (2023). QC lab capacity in Africa.
57
+ 2. USP PQM+. Lab strengthening in 50+ countries.
58
+ 3. WHO Prequalification of QC Laboratories.
59
+ 4. African Medicines Quality Forum.
60
+
61
+ ## Citation
62
+
63
+ ```bibtex
64
+ @dataset{esa_qc_labs_2025,
65
+ title = {Medicine Quality Control Laboratories Dataset},
66
+ author = {{Electric Sheep Africa}},
67
+ year = {2025},
68
+ publisher = {Hugging Face},
69
+ url = {https://huggingface.co/datasets/electricsheepafrica/medicine-quality-control-labs}
70
+ }
71
+ ```
72
+
73
+ ## License
74
+
75
+ [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/)
data/qc_lab_district_basic_lab.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/qc_lab_national_reference_lab.csv ADDED
The diff for this file is too large to render. See raw diff
 
data/qc_lab_who_prequalified_lab.csv ADDED
The diff for this file is too large to render. See raw diff
 
generate_dataset.py ADDED
@@ -0,0 +1,188 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Literature-Informed Medicine Quality Control Laboratories Dataset
4
+ ==================================================================
5
+
6
+ Each record = ONE QC laboratory assessment/performance record.
7
+
8
+ Sources (v2.0):
9
+ [1] WHO (2023). Only 30% of African countries have a functional
10
+ national QC lab. Many labs lack ISO 17025 accreditation.
11
+ [2] USP PQM+. Supported 50+ labs globally. Equipment maintenance
12
+ and reagent supply are critical bottlenecks.
13
+ [3] WHO Prequalification of QC Labs. Only ~10 WHO-prequalified
14
+ QC labs in Africa (out of ~60 globally).
15
+ [4] African Medicines Quality Forum. Lab networking for
16
+ proficiency testing and harmonized methods.
17
+ [5] Lancet Commission (2017). QC lab capacity directly impacts
18
+ SF medicine detection and regulatory enforcement.
19
+ """
20
+
21
+ import numpy as np
22
+ import pandas as pd
23
+ import argparse
24
+ import os
25
+
26
+ EQUIPMENT_TYPES = [
27
+ 'HPLC', 'UV_Vis_spectrophotometer', 'dissolution_apparatus',
28
+ 'disintegration_tester', 'Karl_Fischer_titrator', 'IR_spectrophotometer',
29
+ 'mass_spectrometer', 'GC', 'TLC_equipment', 'pH_meter',
30
+ 'analytical_balance', 'stability_chamber',
31
+ ]
32
+
33
+ TEST_TYPES = [
34
+ 'identity', 'assay_API_content', 'dissolution', 'disintegration',
35
+ 'uniformity_content', 'uniformity_mass', 'moisture_content',
36
+ 'impurity_related_substances', 'microbial_limit', 'sterility',
37
+ 'endotoxin', 'particle_size',
38
+ ]
39
+
40
+ SCENARIOS = {
41
+ 'who_prequalified_lab': {
42
+ 'lab_tier': 'WHO_prequalified',
43
+ 'ISO_17025': True,
44
+ 'staff_analysts': 20,
45
+ 'equipment_functional_rate': 0.92,
46
+ 'samples_per_year': 5000,
47
+ 'turnaround_days': 10,
48
+ 'proficiency_testing_pass': 0.95,
49
+ 'reagent_stockout_rate': 0.05,
50
+ 'budget_usd': 800000,
51
+ 'accreditation_scope_tests': 10,
52
+ },
53
+ 'national_reference_lab': {
54
+ 'lab_tier': 'national_reference',
55
+ 'ISO_17025': False,
56
+ 'staff_analysts': 8,
57
+ 'equipment_functional_rate': 0.65,
58
+ 'samples_per_year': 1500,
59
+ 'turnaround_days': 25,
60
+ 'proficiency_testing_pass': 0.70,
61
+ 'reagent_stockout_rate': 0.25,
62
+ 'budget_usd': 200000,
63
+ 'accreditation_scope_tests': 5,
64
+ },
65
+ 'district_basic_lab': {
66
+ 'lab_tier': 'district_basic',
67
+ 'ISO_17025': False,
68
+ 'staff_analysts': 2,
69
+ 'equipment_functional_rate': 0.30,
70
+ 'samples_per_year': 200,
71
+ 'turnaround_days': 45,
72
+ 'proficiency_testing_pass': 0.35,
73
+ 'reagent_stockout_rate': 0.55,
74
+ 'budget_usd': 30000,
75
+ 'accreditation_scope_tests': 2,
76
+ },
77
+ }
78
+
79
+
80
+ def generate_dataset(n=10000, seed=42, scenario='national_reference_lab'):
81
+ rng = np.random.default_rng(seed)
82
+ sc = SCENARIOS[scenario]
83
+ records = []
84
+
85
+ for idx in range(n):
86
+ rec = {'id': idx + 1}
87
+ rec['lab_tier'] = sc['lab_tier']
88
+ rec['lab_id'] = f"QCL_{rng.integers(1, 100):03d}"
89
+ rec['country_id'] = f"C_{rng.integers(1, 55):03d}"
90
+ rec['region_type'] = rng.choice(['urban', 'peri_urban', 'rural'],
91
+ p=[0.70, 0.20, 0.10] if scenario == 'who_prequalified_lab'
92
+ else ([0.50, 0.30, 0.20] if scenario == 'national_reference_lab'
93
+ else [0.20, 0.30, 0.50]))
94
+
95
+ rec['ISO_17025_accredited'] = 1 if sc['ISO_17025'] else (
96
+ 1 if rng.random() < 0.05 else 0)
97
+ rec['WHO_prequalified_lab'] = 1 if scenario == 'who_prequalified_lab' else 0
98
+ rec['staff_analysts'] = max(1, int(rng.poisson(sc['staff_analysts'])))
99
+ rec['staff_with_MSc_PhD'] = max(0, int(rec['staff_analysts'] * np.clip(
100
+ rng.normal(0.50 if scenario == 'who_prequalified_lab' else
101
+ (0.25 if scenario == 'national_reference_lab' else 0.05), 0.10),
102
+ 0, 0.80)))
103
+ rec['continuous_training_hours_per_year'] = max(0, int(rng.normal(
104
+ 80 if scenario == 'who_prequalified_lab' else
105
+ (30 if scenario == 'national_reference_lab' else 5), 15)))
106
+
107
+ rec['annual_budget_usd'] = max(5000, int(rng.lognormal(
108
+ np.log(sc['budget_usd']), 0.3)))
109
+ rec['budget_from_government_pct'] = round(np.clip(
110
+ rng.normal(60 if scenario == 'who_prequalified_lab' else
111
+ (40 if scenario == 'national_reference_lab' else 20), 15), 5, 95), 1)
112
+ rec['budget_from_donors_pct'] = round(100 - rec['budget_from_government_pct'] -
113
+ np.clip(rng.normal(10, 5), 0, 30), 1)
114
+
115
+ # Equipment
116
+ rec['total_equipment_items'] = max(3, int(rng.poisson(
117
+ len(EQUIPMENT_TYPES) if scenario == 'who_prequalified_lab' else
118
+ (8 if scenario == 'national_reference_lab' else 4))))
119
+ rec['equipment_functional_pct'] = round(np.clip(
120
+ rng.normal(sc['equipment_functional_rate'] * 100, 8), 10, 100), 1)
121
+ rec['HPLC_available'] = 1 if scenario != 'district_basic_lab' or rng.random() < 0.10 else 0
122
+ rec['dissolution_available'] = 1 if scenario == 'who_prequalified_lab' or (
123
+ scenario == 'national_reference_lab' and rng.random() < 0.60) else 0
124
+ rec['mass_spec_available'] = 1 if scenario == 'who_prequalified_lab' and rng.random() < 0.70 else 0
125
+
126
+ rec['reagent_stockout_days_per_year'] = max(0, int(rng.exponential(
127
+ sc['reagent_stockout_rate'] * 365 * 0.3)))
128
+ rec['reference_standards_available'] = 1 if rng.random() < (
129
+ 0.95 if scenario == 'who_prequalified_lab' else
130
+ (0.55 if scenario == 'national_reference_lab' else 0.15)) else 0
131
+
132
+ # Performance
133
+ rec['samples_tested_per_year'] = max(10, int(rng.poisson(sc['samples_per_year'])))
134
+ rec['turnaround_days_median'] = max(1, int(rng.exponential(sc['turnaround_days'] * 0.6)))
135
+ rec['test_types_offered'] = min(len(TEST_TYPES), max(1, int(rng.poisson(
136
+ sc['accreditation_scope_tests']))))
137
+
138
+ rec['proficiency_testing_enrolled'] = 1 if rng.random() < (
139
+ 0.98 if scenario == 'who_prequalified_lab' else
140
+ (0.50 if scenario == 'national_reference_lab' else 0.08)) else 0
141
+ rec['proficiency_testing_pass_rate'] = round(np.clip(
142
+ rng.normal(sc['proficiency_testing_pass'] * 100, 8), 0, 100), 1) if rec['proficiency_testing_enrolled'] else 0
143
+
144
+ rec['internal_audit_conducted'] = 1 if rng.random() < (
145
+ 0.95 if scenario == 'who_prequalified_lab' else
146
+ (0.35 if scenario == 'national_reference_lab' else 0.05)) else 0
147
+ rec['CAPA_system_functional'] = 1 if rng.random() < (
148
+ 0.90 if scenario == 'who_prequalified_lab' else
149
+ (0.25 if scenario == 'national_reference_lab' else 0.03)) else 0
150
+
151
+ rec['sf_detection_rate_pct'] = round(np.clip(
152
+ rng.normal(18 if scenario == 'who_prequalified_lab' else
153
+ (22 if scenario == 'national_reference_lab' else 35), 5), 2, 60), 1)
154
+ rec['confirmatory_testing_capacity'] = 1 if scenario == 'who_prequalified_lab' or (
155
+ scenario == 'national_reference_lab' and rng.random() < 0.40) else 0
156
+
157
+ rec['year'] = rng.choice([2020, 2021, 2022, 2023, 2024],
158
+ p=[0.10, 0.15, 0.20, 0.25, 0.30])
159
+
160
+ records.append(rec)
161
+
162
+ df = pd.DataFrame(records)
163
+ print(f"\n{'='*65}")
164
+ print(f"QC Labs — {scenario} (n={n}, seed={seed})")
165
+ print(f"{'='*65}")
166
+ print(f" Lab tier: {sc['lab_tier']}")
167
+ print(f" Avg staff: {df['staff_analysts'].mean():.0f}")
168
+ print(f" Equipment functional: {df['equipment_functional_pct'].mean():.0f}%")
169
+ print(f" Samples/year: {df['samples_tested_per_year'].mean():.0f}")
170
+ print(f" Proficiency pass: {df[df['proficiency_testing_enrolled']==1]['proficiency_testing_pass_rate'].mean():.0f}%")
171
+ return df
172
+
173
+
174
+ if __name__ == '__main__':
175
+ parser = argparse.ArgumentParser()
176
+ parser.add_argument('--all-scenarios', action='store_true')
177
+ parser.add_argument('--n', type=int, default=10000)
178
+ parser.add_argument('--seed', type=int, default=42)
179
+ args = parser.parse_args()
180
+ os.makedirs('data', exist_ok=True)
181
+ if args.all_scenarios:
182
+ for sc in SCENARIOS:
183
+ df = generate_dataset(n=args.n, seed=args.seed, scenario=sc)
184
+ df.to_csv(os.path.join('data', f'qc_lab_{sc}.csv'), index=False)
185
+ print(f" -> Saved\n")
186
+ else:
187
+ df = generate_dataset(n=args.n, seed=args.seed)
188
+ df.to_csv(os.path.join('data', 'qc_lab_national_reference_lab.csv'), index=False)
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,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Validation & Diagnostic Visualization for Medicine Quality Control Laboratories Dataset."""
3
+
4
+ import pandas as pd
5
+ import numpy as np
6
+ import matplotlib.pyplot as plt
7
+ import os
8
+
9
+ SCENARIOS = ['who_prequalified_lab', 'national_reference_lab', 'district_basic_lab']
10
+
11
+
12
+ def load_scenarios(data_dir='data'):
13
+ dfs = {}
14
+ for sc in SCENARIOS:
15
+ path = os.path.join(data_dir, f'qc_lab_{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, 24))
23
+ fig.suptitle(
24
+ 'Medicine Quality Control Laboratories — Validation Report\n'
25
+ '(WHO-PQ Lab → National Reference → District Basic)',
26
+ fontsize=15, fontweight='bold', y=0.99)
27
+ colors = ['#2ecc71', '#f39c12', '#e74c3c']
28
+ x = np.arange(len(SCENARIOS))
29
+ labels = ['WHO-PQ', 'National Ref', 'District']
30
+
31
+ ax = axes[0, 0]
32
+ staff = [dfs[sc]['staff_analysts'].mean() for sc in SCENARIOS if sc in dfs]
33
+ ax.bar(x, staff, color=colors, alpha=0.8)
34
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
35
+ for i, v in enumerate(staff):
36
+ ax.text(i, v+0.3, f'{v:.0f}', ha='center', fontsize=10, fontweight='bold')
37
+ ax.set_ylabel('Staff'); ax.set_title('Average Analyst Staff')
38
+
39
+ ax = axes[0, 1]
40
+ equip = [dfs[sc]['equipment_functional_pct'].mean() for sc in SCENARIOS if sc in dfs]
41
+ ax.bar(x, equip, color=colors, alpha=0.8)
42
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
43
+ for i, v in enumerate(equip):
44
+ ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
45
+ ax.set_ylabel('Rate (%)'); ax.set_title('Equipment Functional Rate')
46
+
47
+ ax = axes[1, 0]
48
+ samp = [dfs[sc]['samples_tested_per_year'].mean() for sc in SCENARIOS if sc in dfs]
49
+ ax.bar(x, samp, color=colors, alpha=0.8)
50
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
51
+ for i, v in enumerate(samp):
52
+ ax.text(i, v+30, f'{v:.0f}', ha='center', fontsize=10, fontweight='bold')
53
+ ax.set_ylabel('Samples/Year'); ax.set_title('Annual Testing Volume')
54
+
55
+ ax = axes[1, 1]
56
+ prof = []
57
+ for sc in SCENARIOS:
58
+ if sc in dfs:
59
+ enrolled = dfs[sc][dfs[sc]['proficiency_testing_enrolled']==1]
60
+ prof.append(enrolled['proficiency_testing_pass_rate'].mean() if len(enrolled) > 0 else 0)
61
+ ax.bar(x, prof, color=colors, alpha=0.8)
62
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
63
+ for i, v in enumerate(prof):
64
+ ax.text(i, v+1, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
65
+ ax.set_ylabel('Pass Rate (%)'); ax.set_title('Proficiency Testing Pass Rate')
66
+
67
+ ax = axes[2, 0]
68
+ tat = [dfs[sc]['turnaround_days_median'].median() for sc in SCENARIOS if sc in dfs]
69
+ ax.bar(x, tat, color=colors, alpha=0.8)
70
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
71
+ for i, v in enumerate(tat):
72
+ ax.text(i, v+0.5, f'{v:.0f}d', ha='center', fontsize=10, fontweight='bold')
73
+ ax.set_ylabel('Days'); ax.set_title('Median Turnaround Time')
74
+
75
+ ax = axes[2, 1]
76
+ budget = [dfs[sc]['annual_budget_usd'].mean()/1000 for sc in SCENARIOS if sc in dfs]
77
+ ax.bar(x, budget, color=colors, alpha=0.8)
78
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
79
+ for i, v in enumerate(budget):
80
+ ax.text(i, v+5, f'${v:.0f}K', ha='center', fontsize=10, fontweight='bold')
81
+ ax.set_ylabel('Budget (USD K)'); ax.set_title('Average Annual Budget')
82
+
83
+ ax = axes[3, 0]
84
+ sf = [dfs[sc]['sf_detection_rate_pct'].mean() for sc in SCENARIOS if sc in dfs]
85
+ ax.bar(x, sf, color=colors, alpha=0.8)
86
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
87
+ for i, v in enumerate(sf):
88
+ ax.text(i, v+0.5, f'{v:.0f}%', ha='center', fontsize=10, fontweight='bold')
89
+ ax.set_ylabel('SF Rate (%)'); ax.set_title('SF Detection Rate')
90
+
91
+ ax = axes[3, 1]
92
+ stockout = [dfs[sc]['reagent_stockout_days_per_year'].mean() for sc in SCENARIOS if sc in dfs]
93
+ ax.bar(x, stockout, color=colors, alpha=0.8)
94
+ ax.set_xticks(x); ax.set_xticklabels(labels, fontsize=9)
95
+ for i, v in enumerate(stockout):
96
+ ax.text(i, v+0.5, f'{v:.0f}d', ha='center', fontsize=10, fontweight='bold')
97
+ ax.set_ylabel('Days/Year'); ax.set_title('Reagent Stockout Days')
98
+
99
+ plt.tight_layout(rect=[0, 0, 1, 0.97])
100
+ plt.savefig(output, dpi=150, bbox_inches='tight')
101
+ print(f'Saved validation report to {output}')
102
+ plt.close()
103
+
104
+
105
+ if __name__ == '__main__':
106
+ dfs = load_scenarios()
107
+ if dfs:
108
+ make_report(dfs)
validation_report.png ADDED

Git LFS Details

  • SHA256: 5b059b4b2dfc39b52d43acccfb0af82c23a7b0df9844e33e2b81a8b2db240c92
  • Pointer size: 131 Bytes
  • Size of remote file: 252 kB