Kossisoroyce's picture
Upload folder using huggingface_hub
70ebbff verified
Raw
History Blame
8.1 kB
#!/usr/bin/env python3
"""
AI & Clinical Decision Support Dataset
==========================================
Each record = ONE AI/CDSS deployment or interaction event.
Literature-Grounded Parameterization:
[1] Wahl B et al. (2018). AI for global health in SSA.
BMJ Glob Health. DOI: 10.1136/bmjgh-2018-000798
- AI applications: diagnosis, triage, drug discovery
- Most SSA AI health projects: pilot stage
- Chest X-ray AI most deployed (TB screening)
[2] Topol EJ (2019). High-performance medicine with AI.
Nat Med. DOI: 10.1038/s41591-018-0300-7
- CDSS improves diagnostic accuracy 10-30%
- AI radiology, pathology, dermatology leading domains
- Validation in local populations critical
[3] Mollura DJ et al. (2020). AI for radiology in LMICs.
Radiology. DOI: 10.1148/radiol.2020201434
- AI TB detection: sensitivity 90-98%
- Diabetic retinopathy screening AI deployed
- Barriers: data quality, infrastructure, regulation
"""
import numpy as np, pandas as pd, argparse, os
SCENARIOS = {
'ai_deployed': {
'exemplar': 'South Africa/Kenya/Rwanda (urban)',
'ai_available': 0.12,
'cdss_available': 0.15,
'ai_radiology': 0.08,
'ai_pathology': 0.03,
'ai_dermatology': 0.02,
'ai_triage': 0.05,
'recommendation_followed': 0.55,
'diagnostic_accuracy_boost': 0.20,
'user_trust': 0.50,
'internet_required': 0.70,
'validated_local': 0.15,
},
'ai_pilot': {
'exemplar': 'Kenya (district)/Ghana/Tanzania/Ethiopia',
'ai_available': 0.03,
'cdss_available': 0.05,
'ai_radiology': 0.02,
'ai_pathology': 0.005,
'ai_dermatology': 0.005,
'ai_triage': 0.01,
'recommendation_followed': 0.35,
'diagnostic_accuracy_boost': 0.12,
'user_trust': 0.30,
'internet_required': 0.80,
'validated_local': 0.05,
},
'ai_absent': {
'exemplar': 'DRC/CAR/Sierra Leone/Niger (rural)',
'ai_available': 0.005,
'cdss_available': 0.01,
'ai_radiology': 0.002,
'ai_pathology': 0.001,
'ai_dermatology': 0.001,
'ai_triage': 0.002,
'recommendation_followed': 0.20,
'diagnostic_accuracy_boost': 0.05,
'user_trust': 0.15,
'internet_required': 0.90,
'validated_local': 0.01,
},
}
def generate_dataset(n=10000, seed=42, scenario='ai_pilot'):
rng = np.random.default_rng(seed)
sc = SCENARIOS[scenario]
records = []
for idx in range(n):
rec = {'id': idx + 1}
rec['facility_level'] = rng.choice(['tertiary','regional','district','health_centre','clinic','community'],
p=[0.08, 0.12, 0.25, 0.30, 0.15, 0.10])
rec['location'] = rng.choice(['urban','peri_urban','rural','remote'], p=[0.25, 0.20, 0.30, 0.25])
tier = 1.5 if rec['facility_level'] in ['tertiary','regional'] else 0.6
urban = 1.3 if rec['location'] in ['urban','peri_urban'] else 0.7
# Infrastructure
rec['internet_available'] = 1 if rng.random() < min(0.90, 0.35*urban*tier) else 0
rec['power_reliable'] = 1 if rng.random() < min(0.90, 0.40*urban) else 0
rec['smartphone_available'] = 1 if rng.random() < min(0.90, 0.50*urban) else 0
# AI/CDSS availability
rec['ai_tool_available'] = 1 if rng.random() < min(0.80, sc['ai_available']*tier*urban) else 0
rec['cdss_available'] = 1 if rng.random() < min(0.80, sc['cdss_available']*tier*urban) else 0
# AI domain
rec['ai_domain'] = rng.choice([
'tb_xray_screening','diabetic_retinopathy','dermatology','pathology',
'triage_severity','drug_interaction','maternal_risk','malaria_microscopy',
'ecg_interpretation','clinical_guidelines','other'],
p=[0.18, 0.10, 0.08, 0.06, 0.12, 0.08, 0.10, 0.08, 0.05, 0.10, 0.05])
# AI tool specifics
rec['ai_type'] = rng.choice(['image_recognition','nlp','predictive_model','rule_based','hybrid'],
p=[0.30, 0.10, 0.20, 0.25, 0.15])
dp = np.array([0.30*urban, 0.20, max(0.05, 0.30-0.15*urban), 0.15])
dp = dp / dp.sum()
rec['deployment_mode'] = rng.choice(['cloud','edge_device','offline','hybrid'], p=dp)
rec['open_source'] = 1 if rng.random() < 0.40 else 0
rec['regulatory_approved'] = 1 if (rec['ai_tool_available'] and rng.random() < 0.15) else 0
rec['validated_local_population'] = 1 if rng.random() < sc['validated_local'] else 0
# Usage
rec['ai_used_this_encounter'] = 1 if (rec['ai_tool_available'] and rng.random() < 0.60) else 0
rec['recommendation_generated'] = 1 if (rec['ai_used_this_encounter'] and rng.random() < 0.80) else 0
rec['recommendation_followed'] = 1 if (rec['recommendation_generated'] and rng.random() < sc['recommendation_followed']) else 0
rec['recommendation_overridden'] = 1 if (rec['recommendation_generated'] and not rec['recommendation_followed'] and rng.random() < 0.50) else 0
rec['override_reason'] = rng.choice(['clinical_judgment','patient_preference','data_quality','not_applicable','other'],
p=[0.40, 0.15, 0.20, 0.15, 0.10]) if rec['recommendation_overridden'] else 'na'
# Outcomes
rec['diagnostic_accuracy_improved'] = 1 if (rec['ai_used_this_encounter'] and rng.random() < sc['diagnostic_accuracy_boost']) else 0
rec['time_saved_minutes'] = max(0, int(rng.normal(10, 5))) if rec['ai_used_this_encounter'] else 0
rec['patient_outcome_improved'] = 1 if (rec['recommendation_followed'] and rng.random() < 0.30) else 0
rec['false_positive'] = 1 if (rec['ai_used_this_encounter'] and rng.random() < 0.08) else 0
rec['false_negative'] = 1 if (rec['ai_used_this_encounter'] and rng.random() < 0.05) else 0
# User experience
rec['provider_trust_ai'] = int(np.clip(rng.normal(6 if sc['user_trust']>0.4 else 4, 2), 1, 10))
rec['training_received'] = 1 if rng.random() < sc['ai_available']*3 else 0
rec['ease_of_use_score'] = int(np.clip(rng.normal(6 if sc['ai_available']>0.05 else 4, 2), 1, 10))
# Barriers
rec['barrier_infrastructure'] = 1 if not rec['internet_available'] else 0
rec['barrier_trust'] = 1 if rng.random() < max(0.10, 0.50-sc['user_trust']) else 0
rec['barrier_training'] = 1 if not rec['training_received'] else 0
rec['barrier_regulation'] = 1 if rng.random() < 0.30 else 0
rec['barrier_data_quality'] = 1 if rng.random() < 0.35 else 0
rec['barrier_cost'] = 1 if rng.random() < 0.40 else 0
rec['barrier_bias_concern'] = 1 if rng.random() < 0.20 else 0
rec['year'] = rng.choice([2019,2020,2021,2022,2023], p=[0.05,0.12,0.20,0.28,0.35])
records.append(rec)
df = pd.DataFrame(records)
print(f"\n{'='*60}\nAI & Clinical Decision Support — {scenario} ({sc['exemplar']})")
print(f" AI available: {df['ai_tool_available'].mean()*100:.1f}% | Used: {df['ai_used_this_encounter'].mean()*100:.1f}%")
print(f" Rec followed: {df['recommendation_followed'].mean()*100:.1f}% | Accuracy boost: {df['diagnostic_accuracy_improved'].mean()*100:.1f}%")
print(f" Trust score: {df['provider_trust_ai'].mean():.1f}/10 | Validated local: {df['validated_local_population'].mean()*100:.1f}%")
return df
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--all-scenarios', action='store_true')
parser.add_argument('--n', type=int, default=10000)
parser.add_argument('--seed', type=int, default=42)
args = parser.parse_args()
os.makedirs('data', exist_ok=True)
if args.all_scenarios:
for sc in SCENARIOS:
df = generate_dataset(n=args.n, seed=args.seed, scenario=sc)
df.to_csv(os.path.join('data', f'ai_cdss_{sc}.csv'), index=False)
print(f" -> Saved\n")
else:
df = generate_dataset(n=args.n, seed=args.seed)
df.to_csv(os.path.join('data', 'ai_cdss_ai_pilot.csv'), index=False)