Prediksi Stroke Berbasis Decision Tree
Analisis data kesehatan komprehensif menggunakan dataset healthcare-dataset-stroke-data.csv. Algoritma Decision Tree dikonfigurasi dengan teknik pembebanan kelas seimbang (Class Weight Balanced) untuk menangani ketidakseimbangan kelas imbalanced yang ekstrem pada variabel target Stroke
Jumlah data
5.110
11 kolom
Kasus stroke
249
4.87% dari total
Rata-rata umur
43.2
penderita stroke: 67.7
Rata-rata gula darah
106.1
penderita stroke: 132.5
Performa Model (data uji)
Data latih 4088 · data uji 1022 (split 80/20, stratified). Karena kasus stroke hanya ~5%, model memakai class_weight = balanced agar lebih peka mendeteksi stroke (recall tinggi).
Confusion Matrix
Prediksi: Tidak
Prediksi: Stroke
Aktual: Tidak
705
267
Aktual: Stroke
14
36
Model berhasil mendeteksi 36 dari 50 kasus stroke pada data uji.
Kepentingan Fitur
Statistik Deskriptif
| Statistik | Umur | Gula darah | BMI |
|---|---|---|---|
| count | 5110.0 | 5110.0 | 4909.0 |
| mean | 43.23 | 106.15 | 28.89 |
| std | 22.61 | 45.28 | 7.85 |
| min | 0.08 | 55.12 | 10.3 |
| 25% | 25.0 | 77.24 | 23.5 |
| 50% | 45.0 | 91.88 | 28.1 |
| 75% | 61.0 | 114.09 | 33.1 |
| max | 82.0 | 271.74 | 97.6 |
201 data BMI kosong (N/A) diisi dengan nilai median saat pelatihan model.
Aturan Decision Tree (4 level teratas)
|--- num__age <= 47.5 | |--- num__age <= 37.5 | | |--- num__age <= 1.4 | | | |--- num__bmi <= 19.8 | | | | |--- class: 0 | | | |--- num__bmi > 19.8 | | | | |--- class: 1 | | |--- num__age > 1.4 | | | |--- class: 0 | |--- num__age > 37.5 | | |--- num__bmi <= 45.7 | | | |--- num__avg_glucose_level <= 59.0 | | | | |--- class: 0 | | | |--- num__avg_glucose_level > 59.0 | | | | |--- cat__smoking_status_formerly smoked <= 0.5 | | | | | |--- truncated branch of depth 2 | | | | |--- cat__smoking_status_formerly smoked > 0.5 | | | | | |--- truncated branch of depth 2 | | |--- num__bmi > 45.7 | | | |--- class: 1 |--- num__age > 47.5 | |--- num__age <= 67.5 | | |--- num__bmi <= 27.2 | | | |--- num__bmi <= 26.4 | | | | |--- cat__smoking_status_smokes <= 0.5 | | | | | |--- truncated branch of depth 2 | | | | |--- cat__smoking_status_smokes > 0.5 | | | | | |--- truncated branch of depth 2 | | | |--- num__bmi > 26.4 | | | | |--- class: 0 | | |--- num__bmi > 27.2 | | | |--- num__bmi <= 28.6 | | | | |--- num__age <= 53.5 | | | | | |--- truncated branch of depth 2 | | | | |--- num__age > 53.5 | | | | | |--- truncated branch of depth 2 | | | |--- num__bmi > 28.6 | | | | |--- num__heart_disease <= 0.5 | | | | | |--- truncated branch of depth 2 | | | | |--- num__heart_disease > 0.5 | | | | | |--- truncated branch of depth 2 | |--- num__age > 67.5 | | |--- num__age <= 73.5 | | | |--- num__avg_glucose_level <= 177.0 | | | | |--- num__avg_glucose_level <= 94.5 | | | | | |--- truncated branch of depth 2 | | | | |--- num__avg_glucose_level > 94.5 | | | | | |--- truncated branch of depth 2 | | | |--- num__avg_glucose_level > 177.0 | | | | |--- num__bmi <= 28.1 | | | | | |--- class: 1 | | | | |--- num__bmi > 28.1 | | | | | |--- truncated branch of depth 2 | | |--- num__age > 73.5 | | | |--- num__bmi <= 34.2 | | | | |--- num__bmi <= 27.9 | | | | | |--- truncated branch of depth 2 | | | | |--- num__bmi > 27.9 | | | | | |--- truncated branch of depth 2 | | | |--- num__bmi > 34.2 | | | | |--- cat__work_type_Private <= 0.5 | | | | | |--- class: 0 | | | | |--- cat__work_type_Private > 0.5 | | | | | |--- class: 1
Cuplikan Data (10 baris pertama)
| gender | age | hypertension | heart_disease | ever_married | work_type | Residence_type | avg_glucose_level | bmi | smoking_status | stroke |
|---|---|---|---|---|---|---|---|---|---|---|
| Male | 67.0 | 0 | 1 | Yes | Private | Urban | 228.69 | 36.6 | formerly smoked | 1 |
| Female | 61.0 | 0 | 0 | Yes | Self-employed | Rural | 202.21 | N/A | never smoked | 1 |
| Male | 80.0 | 0 | 1 | Yes | Private | Rural | 105.92 | 32.5 | never smoked | 1 |
| Female | 49.0 | 0 | 0 | Yes | Private | Urban | 171.23 | 34.4 | smokes | 1 |
| Female | 79.0 | 1 | 0 | Yes | Self-employed | Rural | 174.12 | 24.0 | never smoked | 1 |
| Male | 81.0 | 0 | 0 | Yes | Private | Urban | 186.21 | 29.0 | formerly smoked | 1 |
| Male | 74.0 | 1 | 1 | Yes | Private | Rural | 70.09 | 27.4 | never smoked | 1 |
| Female | 69.0 | 0 | 0 | No | Private | Urban | 94.39 | 22.8 | never smoked | 1 |
| Female | 59.0 | 0 | 0 | Yes | Private | Rural | 76.15 | N/A | Unknown | 1 |
| Female | 78.0 | 0 | 0 | Yes | Private | Urban | 58.57 | 24.2 | Unknown | 1 |