update
Browse files- README.md +64 -60
- create-data.ipynb +22 -167
README.md
CHANGED
|
@@ -1,82 +1,85 @@
|
|
| 1 |
# Synthetic UMKM Dataset Documentation
|
| 2 |
|
| 3 |
## Ringkasan
|
| 4 |
-
Dataset ini adalah **data sintetis** yang
|
| 5 |
-
|
| 6 |
-
## Latar Belakang
|
| 7 |
-
Dalam praktik operasional UMKM, pengambilan keputusan sering dilakukan tanpa dukungan data yang terstruktur dan terintegrasi. Banyak bisnis hanya memantau omzet secara umum, tetapi belum menghubungkan metrik penting lain seperti margin laba bersih, burn rate, retensi pelanggan, kualitas layanan, dan adopsi teknologi digital dalam satu kerangka analisis yang utuh.
|
| 8 |
-
|
| 9 |
-
Kondisi ini menimbulkan beberapa permasalahan utama:
|
| 10 |
-
|
| 11 |
-
- Sulit mendeteksi dini risiko defisit ketika biaya operasional tumbuh lebih cepat daripada pendapatan.
|
| 12 |
-
- Sulit membedakan apakah pertumbuhan bisnis didorong oleh volume transaksi yang sehat atau hanya kenaikan nilai transaksi sesaat.
|
| 13 |
-
- Sulit mengevaluasi dampak kualitas layanan (rating, volatilitas review, latency) terhadap retensi pelanggan.
|
| 14 |
-
- Sulit mengukur kontribusi adopsi digital terhadap efisiensi operasional dan profitabilitas.
|
| 15 |
-
- Sulit menilai tekanan pasar lokal akibat tingkat kompetisi pada area bisnis.
|
| 16 |
-
|
| 17 |
-
Di sisi lain, data riil UMKM sering memiliki kendala akses, privasi, kerahasiaan bisnis, dan kualitas pencatatan yang tidak konsisten. Karena itu, dataset sintetis ini disusun sebagai pendekatan praktis untuk menyediakan data yang aman, terkontrol, dan tetap realistis secara statistik agar dapat digunakan dalam eksplorasi analitik, pengembangan model, serta simulasi pengambilan keputusan berbasis data.
|
| 18 |
|
| 19 |
## Tujuan Dataset
|
| 20 |
-
Dataset
|
| 21 |
|
| 22 |
-
- Skala
|
| 23 |
-
- Efisiensi
|
| 24 |
-
- Kualitas layanan
|
| 25 |
-
- Maturitas
|
| 26 |
-
- Retensi pelanggan
|
| 27 |
-
-
|
| 28 |
-
- Tekanan pasar
|
|
|
|
| 29 |
|
| 30 |
## Struktur Kolom
|
| 31 |
|
| 32 |
| Fitur | Tipe Data | Skala/Satuan | Deskripsi Teknis |
|
| 33 |
|---|---|---|---|
|
| 34 |
-
| `ID` | Integer | Bilangan bulat | Identitas unik baris data
|
| 35 |
-
| `Monthly_Revenue` | Integer | IDR |
|
| 36 |
-
| `Net_Profit_Margin (%)` | Float | Persentase (%) | Rasio laba bersih terhadap
|
| 37 |
-
| `Burn_Rate_Ratio` | Float | Rasio |
|
| 38 |
-
| `Transaction_Count` | Integer | Frekuensi | Jumlah
|
| 39 |
| `Avg_Historical_Rating` | Float | Skala 1-5 | Rata-rata skor penilaian pelanggan. |
|
| 40 |
-
| `Review_Text` | String | Teks |
|
| 41 |
-
| `Review_Volatility` | Float | Indeks |
|
| 42 |
-
| `Business_Tenure_Months` | Integer | Bulan | Lama
|
| 43 |
-
| `Repeat_Order_Rate (%)` | Float | Persentase (%) |
|
| 44 |
-
| `Digital_Adoption_Score` | Float | Skala 1-10 |
|
| 45 |
-
| `Peak_Hour_Latency` | Categorical | `Low`/`Med`/`High` |
|
| 46 |
-
| `Location_Competitiveness` | Integer | Jumlah |
|
|
|
|
|
|
|
| 47 |
|
| 48 |
## Logika Sintesis Data
|
| 49 |
-
Generator tidak
|
| 50 |
-
|
| 51 |
-
1. `Business_Tenure_Months` dan `Location_Competitiveness`
|
| 52 |
-
2. `Digital_Adoption_Score`
|
| 53 |
-
3. `Transaction_Count`
|
| 54 |
-
4. `Monthly_Revenue`
|
| 55 |
-
5. `Peak_Hour_Latency`
|
| 56 |
-
6. `Burn_Rate_Ratio`
|
| 57 |
-
7. `Net_Profit_Margin (%)`
|
| 58 |
-
8. `Repeat_Order_Rate (%)`
|
| 59 |
-
9. `Review_Volatility`
|
| 60 |
-
10. `Avg_Historical_Rating`
|
| 61 |
-
11. `Review_Text`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
## Karakteristik Realisme
|
| 64 |
-
|
| 65 |
-
-
|
| 66 |
-
-
|
| 67 |
-
-
|
|
|
|
| 68 |
|
| 69 |
## Contoh Use Case
|
| 70 |
-
|
| 71 |
-
-
|
| 72 |
-
-
|
| 73 |
-
-
|
|
|
|
| 74 |
|
| 75 |
## Batasan Dataset
|
| 76 |
-
|
| 77 |
-
-
|
| 78 |
-
-
|
| 79 |
-
-
|
|
|
|
| 80 |
|
| 81 |
## Panduan Pemakaian Cepat
|
| 82 |
|
|
@@ -86,7 +89,8 @@ import pandas as pd
|
|
| 86 |
df = pd.read_csv("synthetic_umkm_data.csv")
|
| 87 |
print(df.shape)
|
| 88 |
print(df.head())
|
|
|
|
| 89 |
```
|
| 90 |
|
| 91 |
## Reproducibility
|
| 92 |
-
Generator menggunakan seed tetap (`SEED = 42`)
|
|
|
|
| 1 |
# Synthetic UMKM Dataset Documentation
|
| 2 |
|
| 3 |
## Ringkasan
|
| 4 |
+
Dataset ini adalah **data sintetis** yang meniru karakteristik operasional UMKM secara realistis pada level bulanan. Dataset dirancang untuk eksplorasi data, pemodelan machine learning, simulasi bisnis, dan analisis sentimen pada ulasan pelanggan.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
## Tujuan Dataset
|
| 7 |
+
Dataset memodelkan keterkaitan metrik inti UMKM dalam satu kerangka yang konsisten:
|
| 8 |
|
| 9 |
+
- Skala bisnis: pendapatan dan volume transaksi
|
| 10 |
+
- Efisiensi operasional: burn rate dan margin laba
|
| 11 |
+
- Kualitas layanan: rating, volatility review, dan latency
|
| 12 |
+
- Maturitas usaha: lama operasional
|
| 13 |
+
- Retensi pelanggan: repeat order rate
|
| 14 |
+
- Kematangan digital: digital adoption score
|
| 15 |
+
- Tekanan pasar: competitiveness lokasi
|
| 16 |
+
- Persepsi pelanggan: sentiment score dari teks ulasan
|
| 17 |
|
| 18 |
## Struktur Kolom
|
| 19 |
|
| 20 |
| Fitur | Tipe Data | Skala/Satuan | Deskripsi Teknis |
|
| 21 |
|---|---|---|---|
|
| 22 |
+
| `ID` | Integer | Bilangan bulat | Identitas unik setiap baris data. |
|
| 23 |
+
| `Monthly_Revenue` | Integer | IDR | Total nilai penjualan bulanan. |
|
| 24 |
+
| `Net_Profit_Margin (%)` | Float | Persentase (%) | Rasio laba bersih terhadap pendapatan. |
|
| 25 |
+
| `Burn_Rate_Ratio` | Float | Rasio | Pengeluaran operasional dibanding pendapatan (`> 1.0` cenderung defisit). |
|
| 26 |
+
| `Transaction_Count` | Integer | Frekuensi | Jumlah transaksi unik dalam periode observasi. |
|
| 27 |
| `Avg_Historical_Rating` | Float | Skala 1-5 | Rata-rata skor penilaian pelanggan. |
|
| 28 |
+
| `Review_Text` | String | Teks | Ulasan pelanggan sintetis untuk kebutuhan NLP. |
|
| 29 |
+
| `Review_Volatility` | Float | Indeks | Fluktuasi kualitas layanan/ulasan. |
|
| 30 |
+
| `Business_Tenure_Months` | Integer | Bulan | Lama usaha beroperasi. |
|
| 31 |
+
| `Repeat_Order_Rate (%)` | Float | Persentase (%) | Proporsi repeat order pelanggan. |
|
| 32 |
+
| `Digital_Adoption_Score` | Float | Skala 1-10 | Tingkat adopsi kanal dan proses digital. |
|
| 33 |
+
| `Peak_Hour_Latency` | Categorical | `Low`/`Med`/`High` | Kualitas layanan saat jam sibuk. |
|
| 34 |
+
| `Location_Competitiveness` | Integer | Jumlah | Kerapatan kompetitor di area yang sama. |
|
| 35 |
+
| `Sentiment_Score` | Float | -1.0 s/d 1.0 | Skor sentimen hasil konversi `Review_Text`. |
|
| 36 |
+
| `Class` | Categorical | `Elite`/`Growth`/`Struggling`/`Critical` | Variabel target kelas bisnis (diletakkan pada kolom paling kanan). |
|
| 37 |
|
| 38 |
## Logika Sintesis Data
|
| 39 |
+
Generator tidak mengacak nilai secara independen, tetapi mengikuti logika operasional berikut:
|
| 40 |
+
|
| 41 |
+
1. Bangkitkan faktor dasar: `Business_Tenure_Months` dan `Location_Competitiveness`.
|
| 42 |
+
2. Turunkan `Digital_Adoption_Score` dari maturitas bisnis dengan noise.
|
| 43 |
+
3. Bentuk `Transaction_Count` dari maturitas, adopsi digital, dan kompetisi.
|
| 44 |
+
4. Hitung `Monthly_Revenue` dari `Transaction_Count` x AOV lognormal + noise musiman.
|
| 45 |
+
5. Turunkan `Peak_Hour_Latency` dari tekanan transaksi, adopsi digital, dan kompetisi.
|
| 46 |
+
6. Bentuk `Burn_Rate_Ratio` dari kompetisi, latency, adopsi digital, dan noise.
|
| 47 |
+
7. Hitung `Net_Profit_Margin (%)` dengan hubungan terbalik terhadap burn rate.
|
| 48 |
+
8. Bentuk `Repeat_Order_Rate (%)` dari digital adoption, tenure, kompetisi, dan noise.
|
| 49 |
+
9. Turunkan `Review_Volatility` dari latency dan kondisi burn rate.
|
| 50 |
+
10. Bentuk `Avg_Historical_Rating` dari sinyal kualitas operasional.
|
| 51 |
+
11. Generate `Review_Text` yang konsisten dengan rating, volatility, dan latency.
|
| 52 |
+
12. Konversi `Review_Text` menjadi `Sentiment_Score` berbasis keyword.
|
| 53 |
+
13. Klasifikasikan `Class` menggunakan threshold persentil agar distribusi kelas lebih seimbang.
|
| 54 |
+
|
| 55 |
+
## Logika Variabel Target `Class`
|
| 56 |
+
Label target dibentuk secara rule-based dengan prioritas kondisi dan threshold persentil:
|
| 57 |
+
|
| 58 |
+
- `Elite`: kombinasi margin tinggi, burn rate rendah, repeat order tinggi, dan rating tinggi.
|
| 59 |
+
- `Struggling`: sinyal profitabilitas melemah dan/atau kualitas layanan menurun.
|
| 60 |
+
- `Critical`: kondisi risiko tinggi (burn rate ekstrem, usaha sangat baru di pasar kompetitif, atau kombinasi rugi berat + rating rendah).
|
| 61 |
+
- `Growth`: kondisi default di luar tiga kondisi ekstrem di atas.
|
| 62 |
|
| 63 |
## Karakteristik Realisme
|
| 64 |
+
|
| 65 |
+
- Distribusi finansial menggunakan lognormal agar mengikuti pola skew data ekonomi nyata.
|
| 66 |
+
- Antarvariabel dibangun saling terkait (bukan random independent).
|
| 67 |
+
- Terdapat noise terkontrol untuk menghindari data terlalu sempurna.
|
| 68 |
+
- Ada post-adjustment untuk bisnis dengan burn rate sangat tinggi agar rating dan repeat order tetap masuk akal.
|
| 69 |
|
| 70 |
## Contoh Use Case
|
| 71 |
+
|
| 72 |
+
- EDA: analisis distribusi pendapatan, margin, burn rate, dan segmentasi kelas bisnis.
|
| 73 |
+
- ML klasifikasi: prediksi `Class`.
|
| 74 |
+
- ML regresi: prediksi `Net_Profit_Margin (%)`.
|
| 75 |
+
- NLP: analisis sentimen pada `Review_Text` dan validasi terhadap `Sentiment_Score`.
|
| 76 |
|
| 77 |
## Batasan Dataset
|
| 78 |
+
|
| 79 |
+
- Dataset ini **bukan data riil** dan tidak merepresentasikan entitas bisnis spesifik.
|
| 80 |
+
- Hubungan antarvariabel adalah asumsi desain generator.
|
| 81 |
+
- Tidak ditujukan untuk inferensi kausal kebijakan nyata tanpa kalibrasi ke data empiris.
|
| 82 |
+
- `Review_Text` bersifat template-based, bukan percakapan pengguna asli.
|
| 83 |
|
| 84 |
## Panduan Pemakaian Cepat
|
| 85 |
|
|
|
|
| 89 |
df = pd.read_csv("synthetic_umkm_data.csv")
|
| 90 |
print(df.shape)
|
| 91 |
print(df.head())
|
| 92 |
+
print(df["Class"].value_counts())
|
| 93 |
```
|
| 94 |
|
| 95 |
## Reproducibility
|
| 96 |
+
Generator menggunakan seed tetap (`SEED = 42`) sehingga data dapat direproduksi selama parameter generator tidak diubah.
|
create-data.ipynb
CHANGED
|
@@ -6,7 +6,9 @@
|
|
| 6 |
"metadata": {},
|
| 7 |
"source": [
|
| 8 |
"# Synthetic Dummy Data Generator (UMKM)\n",
|
| 9 |
-
"Notebook ini membuat data sintetis yang meniru pola data bisnis riil untuk
|
|
|
|
|
|
|
| 10 |
"\n",
|
| 11 |
"- Monthly_Revenue (IDR)\n",
|
| 12 |
"- Net_Profit_Margin (%)\n",
|
|
@@ -20,17 +22,28 @@
|
|
| 20 |
"- Digital_Adoption_Score\n",
|
| 21 |
"- Peak_Hour_Latency\n",
|
| 22 |
"- Location_Competitiveness\n",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
"\n",
|
| 24 |
-
"
|
| 25 |
-
"-
|
| 26 |
-
"-
|
| 27 |
"- Noise terkontrol agar data tidak terlalu \"rapi\"\n",
|
| 28 |
-
"- Review teks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
]
|
| 30 |
},
|
| 31 |
{
|
| 32 |
"cell_type": "code",
|
| 33 |
-
"execution_count":
|
| 34 |
"id": "af962614",
|
| 35 |
"metadata": {},
|
| 36 |
"outputs": [
|
|
@@ -128,7 +141,7 @@
|
|
| 128 |
"type": "string"
|
| 129 |
}
|
| 130 |
],
|
| 131 |
-
"ref": "
|
| 132 |
"rows": [
|
| 133 |
[
|
| 134 |
"0",
|
|
@@ -675,7 +688,7 @@
|
|
| 675 |
"type": "unknown"
|
| 676 |
}
|
| 677 |
],
|
| 678 |
-
"ref": "
|
| 679 |
"rows": [
|
| 680 |
[
|
| 681 |
"ID",
|
|
@@ -1455,7 +1468,7 @@
|
|
| 1455 |
" np.random.uniform(3, 30, deficit_mask.sum()),\n",
|
| 1456 |
")\n",
|
| 1457 |
"\n",
|
| 1458 |
-
"# 13) Target
|
| 1459 |
"target_class = np.full(N_SAMPLES, \"Growth\", dtype=object)\n",
|
| 1460 |
"\n",
|
| 1461 |
"elite_mask = (\n",
|
|
@@ -1515,164 +1528,6 @@
|
|
| 1515 |
"print(\"\\nClass counts:\")\n",
|
| 1516 |
"print(df[\"Class\"].value_counts())"
|
| 1517 |
]
|
| 1518 |
-
},
|
| 1519 |
-
{
|
| 1520 |
-
"cell_type": "markdown",
|
| 1521 |
-
"id": "90ebddda",
|
| 1522 |
-
"metadata": {},
|
| 1523 |
-
"source": [
|
| 1524 |
-
"## Class Variable - Balanced Distribution\n",
|
| 1525 |
-
"Dataset dilengkapi dengan variabel target `class` yang mengklasifikasikan setiap UMKM ke dalam 4 kategori bisnis berdasarkan kondisi operasional. Logika menggunakan **percentile-based thresholding** untuk menciptakan distribusi yang lebih balanced dan realistic.\n",
|
| 1526 |
-
"\n",
|
| 1527 |
-
"### Perubahan dari Versi Sebelumnya\n",
|
| 1528 |
-
"\n",
|
| 1529 |
-
"**Masalah yang Diidentifikasi:**\n",
|
| 1530 |
-
"- Dataset sebelumnya sangat imbalanced (93% Growth, 6% Struggling, 0.2% Critical, 0% Elite)\n",
|
| 1531 |
-
"- Penyebabnya bukan hanya di logic classification, tetapi di fundamental logic variabel-variabel input:\n",
|
| 1532 |
-
" - Burn_Rate_Ratio base terlalu rendah → mayoritas bisnis punya burn rate rendah\n",
|
| 1533 |
-
" - Digital_Adoption memiliki efek positif yang terlalu besar\n",
|
| 1534 |
-
" - Noise di variabel tidak cukup untuk create diverse outcomes\n",
|
| 1535 |
-
"\n",
|
| 1536 |
-
"**Perbaikan yang Dilakukan:**\n",
|
| 1537 |
-
"\n",
|
| 1538 |
-
"1. **Burn_Rate_Ratio Logic (Step 6):**\n",
|
| 1539 |
-
" - Base dinaikkan: 0.72 → 0.82\n",
|
| 1540 |
-
" - Noise ditingkatkan: σ=0.08 → σ=0.11 (lebih banyak variance)\n",
|
| 1541 |
-
" - Latency penalty diperkuat: [0, 0.08, 0.18] → [0, 0.10, 0.22]\n",
|
| 1542 |
-
" - Location competitiveness effect: +0.018 (meningkat efeknya)\n",
|
| 1543 |
-
"\n",
|
| 1544 |
-
"2. **Net Profit Margin Logic (Step 7):**\n",
|
| 1545 |
-
" - Base rating lowered: 4.15 → 4.0 (lebih realistis marginal bisnis)\n",
|
| 1546 |
-
" - Noise ditingkatkan: σ=2.8 → σ=3.2\n",
|
| 1547 |
-
" - Ini menghasilkan distribusi margin yang lebih spread\n",
|
| 1548 |
-
"\n",
|
| 1549 |
-
"3. **Digital Adoption Logic (Step 2):**\n",
|
| 1550 |
-
" - Noise ditingkatkan: σ=1.4 → σ=2.2 (lebih independent dari tenure)\n",
|
| 1551 |
-
" - Ini mengurangi strong coupling dengan business maturity\n",
|
| 1552 |
-
"\n",
|
| 1553 |
-
"4. **Transaction Count & Repeat Order (Step 3 & 8):**\n",
|
| 1554 |
-
" - Noise ditambahkan untuk lebih realistic variability\n",
|
| 1555 |
-
" - Repeat Order ratios lebih conservative\n",
|
| 1556 |
-
"\n",
|
| 1557 |
-
"5. **Classification Logic (Step 14):**\n",
|
| 1558 |
-
" - Dari hard-coded thresholds → **Percentile-based thresholds**\n",
|
| 1559 |
-
" - Elite: top 10% dengan kombinasi high margin, low burn, strong rating\n",
|
| 1560 |
-
" - Struggling: bottom 45% dengan kombinasi low margin & high burn, atau high latency & low rating\n",
|
| 1561 |
-
" - Critical: bottom 8% dengan severe burn rate, new+competitive, atau deep losses\n",
|
| 1562 |
-
" - Growth: sisa bisnis (default)\n",
|
| 1563 |
-
"\n",
|
| 1564 |
-
"### Class Distribution Logic (Percentile-Based)\n",
|
| 1565 |
-
"\n",
|
| 1566 |
-
"| Class | % Target | Kriteria |\n",
|
| 1567 |
-
"|-------|----------|----------|\n",
|
| 1568 |
-
"| **Elite** | ~10% | Margin > P70 AND Burn < P25 AND Repeat > P70 AND Rating > P75 |\n",
|
| 1569 |
-
"| **Growth** | ~37% | Default - bisnis dengan metrik moderate / recovering |\n",
|
| 1570 |
-
"| **Struggling** | ~45% | (Margin < P35 AND Burn > P60) OR (High Latency AND Rating < P40) OR (Burn > P75 AND Rating < P65) |\n",
|
| 1571 |
-
"| **Critical** | ~8% | Burn > P92 OR (Tenure < 7 AND Competition ≥ 12) OR (Margin < P5 AND Rating < 3.0) |\n",
|
| 1572 |
-
"\n",
|
| 1573 |
-
"### Kolom Baru\n",
|
| 1574 |
-
"- `class`: Klasifikasi tier (Elite, Growth, Struggling, Critical)\n",
|
| 1575 |
-
"- `Sentiment_Score`: Angka sentimen dari review text, skala -1.0 (sangat negatif) hingga 1.0 (sangat positif)\n",
|
| 1576 |
-
"\n",
|
| 1577 |
-
"### Penggunaan\n",
|
| 1578 |
-
"Dataset dengan balanced class distribution cocok untuk:\n",
|
| 1579 |
-
"- **Classification Model**: Training lebih stabil dengan distribusi lebih balanced\n",
|
| 1580 |
-
"- **Risk Assessment**: Bisa identify minority classes (Elite dan Critical)\n",
|
| 1581 |
-
"\n",
|
| 1582 |
-
"Dokumentasi lengkap di [README.md](README.md)."
|
| 1583 |
-
]
|
| 1584 |
-
},
|
| 1585 |
-
{
|
| 1586 |
-
"cell_type": "code",
|
| 1587 |
-
"execution_count": 21,
|
| 1588 |
-
"id": "b4494280",
|
| 1589 |
-
"metadata": {},
|
| 1590 |
-
"outputs": [
|
| 1591 |
-
{
|
| 1592 |
-
"name": "stdout",
|
| 1593 |
-
"output_type": "stream",
|
| 1594 |
-
"text": [
|
| 1595 |
-
"======================================================================\n",
|
| 1596 |
-
"CLASS DISTRIBUTION - UPDATED\n",
|
| 1597 |
-
"======================================================================\n"
|
| 1598 |
-
]
|
| 1599 |
-
},
|
| 1600 |
-
{
|
| 1601 |
-
"ename": "KeyError",
|
| 1602 |
-
"evalue": "'class'",
|
| 1603 |
-
"output_type": "error",
|
| 1604 |
-
"traceback": [
|
| 1605 |
-
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
|
| 1606 |
-
"\u001b[31mKeyError\u001b[39m Traceback (most recent call last)",
|
| 1607 |
-
"\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\pandas\\core\\indexes\\base.py:3812\u001b[39m, in \u001b[36mIndex.get_loc\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 3811\u001b[39m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m3812\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_engine\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcasted_key\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 3813\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m err:\n",
|
| 1608 |
-
"\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/index.pyx:167\u001b[39m, in \u001b[36mpandas._libs.index.IndexEngine.get_loc\u001b[39m\u001b[34m()\u001b[39m\n",
|
| 1609 |
-
"\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/index.pyx:196\u001b[39m, in \u001b[36mpandas._libs.index.IndexEngine.get_loc\u001b[39m\u001b[34m()\u001b[39m\n",
|
| 1610 |
-
"\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/hashtable_class_helper.pxi:7088\u001b[39m, in \u001b[36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[39m\u001b[34m()\u001b[39m\n",
|
| 1611 |
-
"\u001b[36mFile \u001b[39m\u001b[32mpandas/_libs/hashtable_class_helper.pxi:7096\u001b[39m, in \u001b[36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[39m\u001b[34m()\u001b[39m\n",
|
| 1612 |
-
"\u001b[31mKeyError\u001b[39m: 'class'",
|
| 1613 |
-
"\nThe above exception was the direct cause of the following exception:\n",
|
| 1614 |
-
"\u001b[31mKeyError\u001b[39m Traceback (most recent call last)",
|
| 1615 |
-
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[21]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 3\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33mCLASS DISTRIBUTION - UPDATED\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 4\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[33m=\u001b[39m\u001b[33m\"\u001b[39m * \u001b[32m70\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m class_counts = \u001b[43mdf\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mclass\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m]\u001b[49m.value_counts().sort_index()\n\u001b[32m 7\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33m\"\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[33mClass counts:\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(class_counts)\n",
|
| 1616 |
-
"\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\pandas\\core\\frame.py:4107\u001b[39m, in \u001b[36mDataFrame.__getitem__\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 4105\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.columns.nlevels > \u001b[32m1\u001b[39m:\n\u001b[32m 4106\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._getitem_multilevel(key)\n\u001b[32m-> \u001b[39m\u001b[32m4107\u001b[39m indexer = \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget_loc\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 4108\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m is_integer(indexer):\n\u001b[32m 4109\u001b[39m indexer = [indexer]\n",
|
| 1617 |
-
"\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Roaming\\Python\\Python311\\site-packages\\pandas\\core\\indexes\\base.py:3819\u001b[39m, in \u001b[36mIndex.get_loc\u001b[39m\u001b[34m(self, key)\u001b[39m\n\u001b[32m 3814\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(casted_key, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m (\n\u001b[32m 3815\u001b[39m \u001b[38;5;28misinstance\u001b[39m(casted_key, abc.Iterable)\n\u001b[32m 3816\u001b[39m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28many\u001b[39m(\u001b[38;5;28misinstance\u001b[39m(x, \u001b[38;5;28mslice\u001b[39m) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m casted_key)\n\u001b[32m 3817\u001b[39m ):\n\u001b[32m 3818\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m InvalidIndexError(key)\n\u001b[32m-> \u001b[39m\u001b[32m3819\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyError\u001b[39;00m(key) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01merr\u001b[39;00m\n\u001b[32m 3820\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m:\n\u001b[32m 3821\u001b[39m \u001b[38;5;66;03m# If we have a listlike key, _check_indexing_error will raise\u001b[39;00m\n\u001b[32m 3822\u001b[39m \u001b[38;5;66;03m# InvalidIndexError. Otherwise we fall through and re-raise\u001b[39;00m\n\u001b[32m 3823\u001b[39m \u001b[38;5;66;03m# the TypeError.\u001b[39;00m\n\u001b[32m 3824\u001b[39m \u001b[38;5;28mself\u001b[39m._check_indexing_error(key)\n",
|
| 1618 |
-
"\u001b[31mKeyError\u001b[39m: 'class'"
|
| 1619 |
-
]
|
| 1620 |
-
}
|
| 1621 |
-
],
|
| 1622 |
-
"source": [
|
| 1623 |
-
"\n",
|
| 1624 |
-
"# Verification: Class Distribution\n",
|
| 1625 |
-
"print(\"=\" * 70)\n",
|
| 1626 |
-
"print(\"CLASS DISTRIBUTION - UPDATED\")\n",
|
| 1627 |
-
"print(\"=\" * 70)\n",
|
| 1628 |
-
"\n",
|
| 1629 |
-
"class_counts = df['class'].value_counts().sort_index()\n",
|
| 1630 |
-
"print(\"\\nClass counts:\")\n",
|
| 1631 |
-
"print(class_counts)\n",
|
| 1632 |
-
"\n",
|
| 1633 |
-
"print(\"\\n\\nClass percentages:\")\n",
|
| 1634 |
-
"total = len(df)\n",
|
| 1635 |
-
"for cls in sorted(df['class'].unique()):\n",
|
| 1636 |
-
" if cls in class_counts.index:\n",
|
| 1637 |
-
" count = class_counts[cls]\n",
|
| 1638 |
-
" else:\n",
|
| 1639 |
-
" count = 0\n",
|
| 1640 |
-
" pct = (count / total * 100)\n",
|
| 1641 |
-
" print(f\" {cls:15s}: {count:7,d} ({pct:6.2f}%)\")\n",
|
| 1642 |
-
"\n",
|
| 1643 |
-
"print(\"\\n\\n\" + \"=\" * 70)\n",
|
| 1644 |
-
"print(\"CLASS - METRICS CORRELATION\")\n",
|
| 1645 |
-
"print(\"=\" * 70)\n",
|
| 1646 |
-
"\n",
|
| 1647 |
-
"class_metrics = df.groupby('class')[['Net_Profit_Margin (%)', 'Burn_Rate_Ratio', \n",
|
| 1648 |
-
" 'Repeat_Order_Rate (%)', 'Avg_Historical_Rating', \n",
|
| 1649 |
-
" 'Sentiment_Score']].agg(['mean', 'min', 'max'])\n",
|
| 1650 |
-
"print(class_metrics.round(2))\n",
|
| 1651 |
-
"\n",
|
| 1652 |
-
"print(\"\\n\\n\" + \"=\" * 70)\n",
|
| 1653 |
-
"print(\"BURN_RATE_RATIO DISTRIBUTION\")\n",
|
| 1654 |
-
"print(\"=\" * 70)\n",
|
| 1655 |
-
"print(f\"Mean: {df['Burn_Rate_Ratio'].mean():.3f}\")\n",
|
| 1656 |
-
"print(f\"Std: {df['Burn_Rate_Ratio'].std():.3f}\")\n",
|
| 1657 |
-
"print(f\"Min: {df['Burn_Rate_Ratio'].min():.3f}\")\n",
|
| 1658 |
-
"print(f\"Max: {df['Burn_Rate_Ratio'].max():.3f}\")\n",
|
| 1659 |
-
"print(f\"\\n% with Burn_Rate < 0.75: {(df['Burn_Rate_Ratio'] < 0.75).sum() / len(df) * 100:.1f}%\")\n",
|
| 1660 |
-
"print(f\"% with Burn_Rate < 1.00: {(df['Burn_Rate_Ratio'] < 1.00).sum() / len(df) * 100:.1f}%\")\n",
|
| 1661 |
-
"print(f\"% with Burn_Rate >= 1.00: {(df['Burn_Rate_Ratio'] >= 1.00).sum() / len(df) * 100:.1f}%\")\n",
|
| 1662 |
-
"print(f\"% with Burn_Rate >= 1.20: {(df['Burn_Rate_Ratio'] >= 1.20).sum() / len(df) * 100:.1f}%\")\n",
|
| 1663 |
-
"\n",
|
| 1664 |
-
"print(\"\\n\\n\" + \"=\" * 70)\n",
|
| 1665 |
-
"print(\"NET_PROFIT_MARGIN DISTRIBUTION\")\n",
|
| 1666 |
-
"print(\"=\" * 70)\n",
|
| 1667 |
-
"print(f\"Mean: {df['Net_Profit_Margin (%)'].mean():.2f}%\")\n",
|
| 1668 |
-
"print(f\"Std: {df['Net_Profit_Margin (%)'].std():.2f}%\")\n",
|
| 1669 |
-
"print(f\"Min: {df['Net_Profit_Margin (%)'].min():.2f}%\")\n",
|
| 1670 |
-
"print(f\"Max: {df['Net_Profit_Margin (%)'].max():.2f}%\")\n",
|
| 1671 |
-
"print(f\"\\n% with Profit < 0: {(df['Net_Profit_Margin (%)'] < 0).sum() / len(df) * 100:.1f}%\")\n",
|
| 1672 |
-
"print(f\"% with Profit 0-10%: {((df['Net_Profit_Margin (%)'] >= 0) & (df['Net_Profit_Margin (%)'] < 10)).sum() / len(df) * 100:.1f}%\")\n",
|
| 1673 |
-
"print(f\"% with Profit >= 10%: {(df['Net_Profit_Margin (%)'] >= 10).sum() / len(df) * 100:.1f}%\")\n",
|
| 1674 |
-
"print(f\"% with Profit >= 20%: {(df['Net_Profit_Margin (%)'] >= 20).sum() / len(df) * 100:.1f}%\")\n"
|
| 1675 |
-
]
|
| 1676 |
}
|
| 1677 |
],
|
| 1678 |
"metadata": {
|
|
|
|
| 6 |
"metadata": {},
|
| 7 |
"source": [
|
| 8 |
"# Synthetic Dummy Data Generator (UMKM)\n",
|
| 9 |
+
"Notebook ini membuat data sintetis yang meniru pola data bisnis riil UMKM untuk analisis operasional, NLP, dan klasifikasi bisnis.\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"Fitur utama yang dihasilkan:\n",
|
| 12 |
"\n",
|
| 13 |
"- Monthly_Revenue (IDR)\n",
|
| 14 |
"- Net_Profit_Margin (%)\n",
|
|
|
|
| 22 |
"- Digital_Adoption_Score\n",
|
| 23 |
"- Peak_Hour_Latency\n",
|
| 24 |
"- Location_Competitiveness\n",
|
| 25 |
+
"- Sentiment_Score (-1.0 s/d 1.0)\n",
|
| 26 |
+
"- Class (Elite, Growth, Struggling, Critical)\n",
|
| 27 |
+
"\n",
|
| 28 |
+
"Karakteristik realisme yang dimodelkan:\n",
|
| 29 |
"\n",
|
| 30 |
+
"- Korelasi antar fitur operasional (contoh: adopsi digital cenderung meningkatkan retensi dan rating)\n",
|
| 31 |
+
"- Trade-off bisnis (kompetisi tinggi dan latency tinggi menekan profitabilitas)\n",
|
| 32 |
+
"- Distribusi finansial tidak simetris (AOV lognormal)\n",
|
| 33 |
"- Noise terkontrol agar data tidak terlalu \"rapi\"\n",
|
| 34 |
+
"- Review teks konsisten dengan sinyal kualitas (rating, volatility, latency)\n",
|
| 35 |
+
"- Sentiment score diekstrak dari `Review_Text`\n",
|
| 36 |
+
"\n",
|
| 37 |
+
"Catatan target:\n",
|
| 38 |
+
"\n",
|
| 39 |
+
"- Variabel target adalah `Class` (kolom paling kanan)\n",
|
| 40 |
+
"- Klasifikasi menggunakan threshold berbasis persentil agar distribusi kelas lebih seimbang\n",
|
| 41 |
+
"- Urutan kelas: `Elite`, `Growth`, `Struggling`, `Critical`"
|
| 42 |
]
|
| 43 |
},
|
| 44 |
{
|
| 45 |
"cell_type": "code",
|
| 46 |
+
"execution_count": 29,
|
| 47 |
"id": "af962614",
|
| 48 |
"metadata": {},
|
| 49 |
"outputs": [
|
|
|
|
| 141 |
"type": "string"
|
| 142 |
}
|
| 143 |
],
|
| 144 |
+
"ref": "f3816b53-8a85-4cea-a3c9-d8cfc2031baa",
|
| 145 |
"rows": [
|
| 146 |
[
|
| 147 |
"0",
|
|
|
|
| 688 |
"type": "unknown"
|
| 689 |
}
|
| 690 |
],
|
| 691 |
+
"ref": "97626024-31ed-4e88-8d10-a524d1d63c40",
|
| 692 |
"rows": [
|
| 693 |
[
|
| 694 |
"ID",
|
|
|
|
| 1468 |
" np.random.uniform(3, 30, deficit_mask.sum()),\n",
|
| 1469 |
")\n",
|
| 1470 |
"\n",
|
| 1471 |
+
"# 13) Target Class with percentile-based thresholds (balanced by design)\n",
|
| 1472 |
"target_class = np.full(N_SAMPLES, \"Growth\", dtype=object)\n",
|
| 1473 |
"\n",
|
| 1474 |
"elite_mask = (\n",
|
|
|
|
| 1528 |
"print(\"\\nClass counts:\")\n",
|
| 1529 |
"print(df[\"Class\"].value_counts())"
|
| 1530 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1531 |
}
|
| 1532 |
],
|
| 1533 |
"metadata": {
|