| | |
| | """Validation & Diagnostic Visualization for Oral Health Dataset.""" |
| |
|
| | import pandas as pd |
| | import numpy as np |
| | import matplotlib.pyplot as plt |
| | import os |
| |
|
| | SCENARIOS = ['dental_clinic', 'district_hospital', 'rural_health_centre'] |
| |
|
| |
|
| | def load_scenarios(data_dir='data'): |
| | dfs = {} |
| | for sc in SCENARIOS: |
| | path = os.path.join(data_dir, f'oral_{sc}.csv') |
| | if os.path.exists(path): |
| | dfs[sc] = pd.read_csv(path) |
| | return dfs |
| |
|
| |
|
| | def make_report(dfs, output='validation_report.png'): |
| | fig, axes = plt.subplots(4, 2, figsize=(16, 22)) |
| | fig.suptitle('Oral Health & Dental Disease — Validation Report', |
| | fontsize=16, fontweight='bold', y=0.98) |
| | df = dfs.get('district_hospital', list(dfs.values())[0]) |
| | colors = ['#2ecc71', '#f39c12', '#e74c3c'] |
| |
|
| | ax = axes[0, 0] |
| | conditions = ['dental_caries', 'untreated_caries', 'periodontal_disease', |
| | 'dental_pain', 'dental_abscess', 'tooth_loss'] |
| | c_labels = ['Caries', 'Untreated', 'Periodontal', 'Pain', 'Abscess', 'Tooth Loss'] |
| | vals = [df[c].mean() * 100 if c != 'tooth_loss' else (df[c] > 0).mean() * 100 for c in conditions] |
| | ax.bar(range(6), vals, color='#e74c3c', alpha=0.7) |
| | ax.set_xticks(range(6)) |
| | ax.set_xticklabels(c_labels, fontsize=8, rotation=15) |
| | for i, v in enumerate(vals): |
| | ax.text(i, v + 0.5, f'{v:.0f}%', ha='center', fontsize=8) |
| | ax.set_ylabel('Prevalence (%)') |
| | ax.set_title('Oral Disease Burden (caries most prevalent)') |
| |
|
| | ax = axes[0, 1] |
| | x = np.arange(len(SCENARIOS)) |
| | care = [dfs[sc]['sought_dental_care'].mean() * 100 for sc in SCENARIOS if sc in dfs] |
| | ax.bar(x, care, color=colors, alpha=0.8) |
| | ax.set_xticks(x) |
| | ax.set_xticklabels(['Dental Clinic', 'District', 'Rural'], fontsize=9) |
| | for i, v in enumerate(care): |
| | ax.text(i, v + 0.5, f'{v:.0f}%', ha='center', fontsize=10) |
| | ax.set_ylabel('Care-Seeking Rate (%)') |
| | ax.set_title('Dental Care Access (<1 dentist/100K in SSA)') |
| |
|
| | ax = axes[1, 0] |
| | caries_pts = df[df['dental_caries'] == 1] |
| | if len(caries_pts) > 0: |
| | ax.hist(caries_pts['dmft_score'], bins=20, color='#3498db', alpha=0.7, edgecolor='white') |
| | ax.set_xlabel('DMFT Score') |
| | ax.set_title('DMFT Distribution (mean ~4 in SSA)') |
| |
|
| | ax = axes[1, 1] |
| | treatments = df[df['treatment_received'] != 'none']['treatment_received'].value_counts() |
| | if len(treatments) > 0: |
| | t_colors = ['#e74c3c', '#f39c12', '#3498db', '#2ecc71', '#9b59b6', '#e67e22'] |
| | ax.pie(treatments.values, |
| | labels=[s.replace('_', ' ').title() for s in treatments.index], |
| | autopct='%1.0f%%', colors=t_colors[:len(treatments)], |
| | startangle=90, textprops={'fontsize': 8}) |
| | ax.set_title('Treatment Type (extraction dominates)') |
| |
|
| | ax = axes[2, 0] |
| | barriers = df[df['barrier_to_care'] != 'none']['barrier_to_care'].value_counts() |
| | if len(barriers) > 0: |
| | ax.barh(range(len(barriers)), barriers.values, color='#3498db', alpha=0.8) |
| | ax.set_yticks(range(len(barriers))) |
| | ax.set_yticklabels([s.replace('_', ' ').title() for s in barriers.index], fontsize=8) |
| | ax.set_xlabel('Count') |
| | ax.set_title('Barriers to Dental Care') |
| |
|
| | ax = axes[2, 1] |
| | risks = ['sugary_diet', 'tobacco_use', 'fluoride_toothpaste', 'diabetes'] |
| | r_labels = ['Sugary Diet', 'Tobacco', 'Fluoride Paste', 'Diabetes'] |
| | caries_y = df[df['dental_caries'] == 1] |
| | caries_n = df[df['dental_caries'] == 0] |
| | if len(caries_y) > 0 and len(caries_n) > 0: |
| | vc = [caries_y[r].mean() * 100 for r in risks] |
| | vn = [caries_n[r].mean() * 100 for r in risks] |
| | w = 0.3 |
| | ax.bar(np.arange(4) - w/2, vc, w, label='Caries', color='#e74c3c', alpha=0.8) |
| | ax.bar(np.arange(4) + w/2, vn, w, label='No Caries', color='#2ecc71', alpha=0.8) |
| | ax.set_xticks(np.arange(4)) |
| | ax.set_xticklabels(r_labels, fontsize=8) |
| | ax.set_ylabel('Prevalence (%)') |
| | ax.set_title('Risk Factors vs Caries') |
| | ax.legend(fontsize=8) |
| |
|
| | ax = axes[3, 0] |
| | children = df[df['child'] == 1] |
| | adults = df[df['child'] == 0] |
| | cats = ['Caries', 'Pain', 'Sought Care'] |
| | if len(children) > 0 and len(adults) > 0: |
| | vc = [children['dental_caries'].mean()*100, children['dental_pain'].mean()*100, |
| | children['sought_dental_care'].mean()*100] |
| | va = [adults['dental_caries'].mean()*100, adults['dental_pain'].mean()*100, |
| | adults['sought_dental_care'].mean()*100] |
| | w = 0.3 |
| | ax.bar(np.arange(3) - w/2, vc, w, label='Children', color='#3498db', alpha=0.8) |
| | ax.bar(np.arange(3) + w/2, va, w, label='Adults', color='#e74c3c', alpha=0.8) |
| | ax.set_xticks(np.arange(3)) |
| | ax.set_xticklabels(cats, fontsize=9) |
| | ax.set_ylabel('Rate (%)') |
| | ax.set_title('Children vs Adults') |
| | ax.legend(fontsize=8) |
| |
|
| | ax = axes[3, 1] |
| | brush = df['brushing_frequency'].value_counts() |
| | b_order = ['never', 'occasional', 'once_daily', 'twice_daily'] |
| | vals = [brush.get(b, 0) for b in b_order] |
| | ax.bar(range(4), vals, color=['#e74c3c', '#f39c12', '#3498db', '#2ecc71'], alpha=0.8) |
| | ax.set_xticks(range(4)) |
| | ax.set_xticklabels(['Never', 'Occasional', 'Once/Day', 'Twice/Day'], fontsize=8) |
| | ax.set_ylabel('Count') |
| | ax.set_title('Brushing Frequency') |
| |
|
| | plt.tight_layout(rect=[0, 0, 1, 0.97]) |
| | plt.savefig(output, dpi=150, bbox_inches='tight') |
| | print(f'Saved validation report to {output}') |
| | plt.close() |
| |
|
| |
|
| | if __name__ == '__main__': |
| | dfs = load_scenarios() |
| | if dfs: |
| | make_report(dfs) |
| |
|