binboost 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- binboost-0.2.3/PKG-INFO +129 -0
- binboost-0.2.3/README.md +108 -0
- {binboost-0.2.2 → binboost-0.2.3}/binboost/__init__.py +2 -1
- {binboost-0.2.2 → binboost-0.2.3}/binboost/binarizer.py +1 -1
- {binboost-0.2.2 → binboost-0.2.3}/binboost/binboost.py +35 -13
- {binboost-0.2.2 → binboost-0.2.3}/binboost/loss.py +1 -1
- {binboost-0.2.2 → binboost-0.2.3}/binboost/multiclass.py +11 -11
- {binboost-0.2.2 → binboost-0.2.3}/binboost/rule.py +11 -8
- binboost-0.2.3/binboost.egg-info/PKG-INFO +129 -0
- {binboost-0.2.2 → binboost-0.2.3}/pyproject.toml +1 -1
- {binboost-0.2.2 → binboost-0.2.3}/setup.py +1 -1
- binboost-0.2.2/PKG-INFO +0 -101
- binboost-0.2.2/README.md +0 -80
- binboost-0.2.2/binboost.egg-info/PKG-INFO +0 -101
- {binboost-0.2.2 → binboost-0.2.3}/LICENSE +0 -0
- {binboost-0.2.2 → binboost-0.2.3}/binboost.egg-info/SOURCES.txt +0 -0
- {binboost-0.2.2 → binboost-0.2.3}/binboost.egg-info/dependency_links.txt +0 -0
- {binboost-0.2.2 → binboost-0.2.3}/binboost.egg-info/requires.txt +0 -0
- {binboost-0.2.2 → binboost-0.2.3}/binboost.egg-info/top_level.txt +0 -0
- {binboost-0.2.2 → binboost-0.2.3}/setup.cfg +0 -0
binboost-0.2.3/PKG-INFO
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: binboost
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner
|
|
5
|
+
Author: Rangga Wahyu Pratama
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: gradient boosting,logical rules,binary features,interpretable machine learning
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: numpy>=1.21.0
|
|
17
|
+
Requires-Dist: pandas>=1.3.0
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
|
|
22
|
+
# BinBoost
|
|
23
|
+
|
|
24
|
+
**Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner, dengan Regularisasi Newton-Hessian dan Dukungan Multi-Kelas**
|
|
25
|
+
|
|
26
|
+
BinBoost adalah algoritma klasifikasi gradient boosting yang membangun ensemble aturan logika murni (AND, OR, XOR, termasuk negasi NOT) dengan binarisasi fitur numerik adaptif berbasis gradien pada setiap iterasi boosting. Bobot tiap aturan dihitung dengan pendekatan Newton (memakai Hessian per fungsi loss) dan regularisasi adaptif berbasis dukungan sampel & kompleksitas aturan. Setiap weak learner berupa aturan yang dapat dibaca langsung oleh manusia tanpa memerlukan alat bantu penjelasan pasca-pelatihan.
|
|
27
|
+
|
|
28
|
+
## Kebaruan Utama
|
|
29
|
+
- **Binarisasi adaptif berbasis gradien**: nilai ambang batas fitur numerik dicari per iterasi untuk memaksimalkan korelasi dengan gradien saat ini
|
|
30
|
+
- **Ensemble aturan logika murni**: tidak ada pohon keputusan, setiap weak learner adalah aturan seperti: `(A AND B)`, `(C OR D)`, atau `(A AND NOT B)`
|
|
31
|
+
- **Youden J**: Penggunaan indeks Youden J sebagai `threshold='auto'` bawaan untuk menentukan titik potong prediksi, bukan fixed di 0.5 serta mengoptimalkan sensitivity + specificity pada data training, cocok untuk kasus kelas tidak seimbang
|
|
32
|
+
- **Fitur ternegasi (NOT)**: pencarian aturan otomatis mempertimbangkan dua polaritas (asli dan negasi) untuk tiap kandidat fitur
|
|
33
|
+
- **Bobot aturan berbasis Newton (Hessian)**: bobot dua sisi tiap aturan dihitung dengan `w = G/(H+λ)`, memakai turunan kedua (Hessian) yang sesuai dengan fungsi loss yang dipilih (logistic, focal, atau poly), bukan sekadar rata-rata gradien
|
|
34
|
+
- **Regularisasi adaptif**: `λ` menyesuaikan otomatis terhadap jumlah sampel dan panjang aturan, sehingga aturan dengan cakupan kecil/kompleks ditahan bobotnya secara proporsional
|
|
35
|
+
- **Minimum-gain pruning (`gamma`)**: aturan dengan kontribusi terlalu kecil bisa ditolak sebelum masuk ensemble, membantu mencegah overfitting pada aturan yang terlalu spesifik
|
|
36
|
+
- **Dukungan multi-kelas**: lewat `binboost.multiclass.OneVsRestBinBoost`, BinBoost bisa dipakai untuk klasifikasi dengan lebih dari 2 kelas (strategi One-vs-Rest)
|
|
37
|
+
|
|
38
|
+
## Instalasi
|
|
39
|
+
```bash
|
|
40
|
+
pip install binboost
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Penggunaan Dasar untuk Klasifikasi Biner
|
|
44
|
+
```python
|
|
45
|
+
import numpy as np
|
|
46
|
+
from binboost import BinBoost
|
|
47
|
+
|
|
48
|
+
X = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]], dtype=float)
|
|
49
|
+
y = np.array([1, 0, 1, 0])
|
|
50
|
+
|
|
51
|
+
model = BinBoost(n_estimators=100, learning_rate=0.2, max_rule_length=4)
|
|
52
|
+
model.fit(X, y)
|
|
53
|
+
|
|
54
|
+
print(model.predict(X))
|
|
55
|
+
print(model.predict_proba(X))
|
|
56
|
+
print(model.rules_)
|
|
57
|
+
|
|
58
|
+
import pandas as pd
|
|
59
|
+
print(pd.DataFrame(model.rule_summary_))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Penggunaan Multi-Kelas (>2 kelas)
|
|
63
|
+
Untuk label dengan lebih dari 2 kelas yang saling eksklusif, gunakan `OneVsRestBinBoost` — hyperparameter yang diteruskan persis sama dengan `BinBoost`:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from binboost.multiclass import OneVsRestBinBoost
|
|
67
|
+
|
|
68
|
+
model = OneVsRestBinBoost(
|
|
69
|
+
mode='multiclass',
|
|
70
|
+
n_estimators=100,
|
|
71
|
+
learning_rate=0.2,
|
|
72
|
+
max_rule_length=4,
|
|
73
|
+
lambda0=3.0,
|
|
74
|
+
)
|
|
75
|
+
model.fit(X, y) # y boleh berisi >2 kelas, mis. array string atau integer
|
|
76
|
+
|
|
77
|
+
print(model.predict(X))
|
|
78
|
+
print(model.predict_proba(X)) # dinormalisasi supaya tiap baris berjumlah 1
|
|
79
|
+
print(pd.DataFrame(model.rule_summary_)) # aturan per kelas, kolom 'kelas' menandai sub-model asalnya
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`mode='multilabel'` tersedia untuk kasus di mana satu sampel bisa punya lebih dari satu label positif sekaligus dimana probabilitas tidak dinormalisasi, tiap kelas diputuskan independen.
|
|
83
|
+
|
|
84
|
+
## Hyperparameter Utama
|
|
85
|
+
|
|
86
|
+
| Parameter | Bawaan | Keterangan |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `n_estimators` | 100 | Jumlah iterasi boosting |
|
|
89
|
+
| `learning_rate` | 0.2 | Faktor penyusutan tiap aturan |
|
|
90
|
+
| `loss` | `'logistic'` | Fungsi loss: `'logistic'`, `'focal'`, `'poly'` |
|
|
91
|
+
| `max_rule_length` | 4 | Jumlah maksimum fitur dalam satu aturan |
|
|
92
|
+
| `operators` | `['AND','OR']` | Operator logika yang digunakan ubah `use_xor=True` untuk mengaktifkan XOR |
|
|
93
|
+
| `beam_width` | 5 | Lebar beam search |
|
|
94
|
+
| `binarize_strategy` | `'gradient'` | Strategi binarisasi: `'gradient'`, `'quantile'`, `'uniform'`, `'kmeans'` |
|
|
95
|
+
| `subsample` | 0.8 | Fraksi data per iterasi |
|
|
96
|
+
| `feature_selection_threshold` | 0.0 | Ambang batas persentil gain fitur untuk seleksi kandidat (0.0 = semua fitur) |
|
|
97
|
+
| `min_samples_rule` | 5 | Jumlah/fraksi minimum sampel yang harus memenuhi sebuah aturan |
|
|
98
|
+
| `lambda0` | 3.0 | Konstanta regularisasi Newton adaptif |
|
|
99
|
+
| `gamma` | 0.0 | Ambang minimum gain untuk menerima sebuah aturan (0.0 = tanpa pruning, nonaktif secara bawaan) |
|
|
100
|
+
|
|
101
|
+
Fitur negasi (NOT) aktif otomatis pada pencarian aturan dan bukan hyperparameter yang bisa diatur lewat `BinBoost()` — ini bagian tetap dari mekanisme beam search.
|
|
102
|
+
|
|
103
|
+
## Fitur yang Didukung
|
|
104
|
+
- Fitur biner (0/1): langsung diproses
|
|
105
|
+
- Fitur numerik (int/float): dibinarisasi otomatis per iterasi
|
|
106
|
+
- Fitur kategorikal 3+ kelas: wajib OneHotEncode terlebih dahulu
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from sklearn.preprocessing import OneHotEncoder
|
|
110
|
+
enc = OneHotEncoder(sparse_output=False, drop='first')
|
|
111
|
+
X_encoded = enc.fit_transform(X[['kolom_kategorikal']])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
BinBoost secara otomatis mendeteksi kelompok fitur OneHotEncoding dan mencegah aturan yang tidak masuk akal seperti `(Warna_Merah AND Warna_Biru)`.
|
|
115
|
+
|
|
116
|
+
## Atribut Setelah Pelatihan
|
|
117
|
+
```python
|
|
118
|
+
model.rules_ # daftar teks aturan termasuk NOT jika ada
|
|
119
|
+
model.rule_weights_ # bobot dua sisi [w0, w1] tiap aturan (hasil Newton + regularisasi)
|
|
120
|
+
model.feature_importances_ # skor kepentingan fitur
|
|
121
|
+
model.train_score_ # loss per iterasi
|
|
122
|
+
model.rule_summary_ # ringkasan lengkap atau konversi ke DataFrame
|
|
123
|
+
model.n_rules_ # jumlah aturan aktif
|
|
124
|
+
model.feature_usage_ # frekuensi penggunaan tiap fitur
|
|
125
|
+
model.thresholds_ # riwayat threshold biner per fitur numerik, per iterasi
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Lisensi
|
|
129
|
+
MIT
|
binboost-0.2.3/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# BinBoost
|
|
2
|
+
|
|
3
|
+
**Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner, dengan Regularisasi Newton-Hessian dan Dukungan Multi-Kelas**
|
|
4
|
+
|
|
5
|
+
BinBoost adalah algoritma klasifikasi gradient boosting yang membangun ensemble aturan logika murni (AND, OR, XOR, termasuk negasi NOT) dengan binarisasi fitur numerik adaptif berbasis gradien pada setiap iterasi boosting. Bobot tiap aturan dihitung dengan pendekatan Newton (memakai Hessian per fungsi loss) dan regularisasi adaptif berbasis dukungan sampel & kompleksitas aturan. Setiap weak learner berupa aturan yang dapat dibaca langsung oleh manusia tanpa memerlukan alat bantu penjelasan pasca-pelatihan.
|
|
6
|
+
|
|
7
|
+
## Kebaruan Utama
|
|
8
|
+
- **Binarisasi adaptif berbasis gradien**: nilai ambang batas fitur numerik dicari per iterasi untuk memaksimalkan korelasi dengan gradien saat ini
|
|
9
|
+
- **Ensemble aturan logika murni**: tidak ada pohon keputusan, setiap weak learner adalah aturan seperti: `(A AND B)`, `(C OR D)`, atau `(A AND NOT B)`
|
|
10
|
+
- **Youden J**: Penggunaan indeks Youden J sebagai `threshold='auto'` bawaan untuk menentukan titik potong prediksi, bukan fixed di 0.5 serta mengoptimalkan sensitivity + specificity pada data training, cocok untuk kasus kelas tidak seimbang
|
|
11
|
+
- **Fitur ternegasi (NOT)**: pencarian aturan otomatis mempertimbangkan dua polaritas (asli dan negasi) untuk tiap kandidat fitur
|
|
12
|
+
- **Bobot aturan berbasis Newton (Hessian)**: bobot dua sisi tiap aturan dihitung dengan `w = G/(H+λ)`, memakai turunan kedua (Hessian) yang sesuai dengan fungsi loss yang dipilih (logistic, focal, atau poly), bukan sekadar rata-rata gradien
|
|
13
|
+
- **Regularisasi adaptif**: `λ` menyesuaikan otomatis terhadap jumlah sampel dan panjang aturan, sehingga aturan dengan cakupan kecil/kompleks ditahan bobotnya secara proporsional
|
|
14
|
+
- **Minimum-gain pruning (`gamma`)**: aturan dengan kontribusi terlalu kecil bisa ditolak sebelum masuk ensemble, membantu mencegah overfitting pada aturan yang terlalu spesifik
|
|
15
|
+
- **Dukungan multi-kelas**: lewat `binboost.multiclass.OneVsRestBinBoost`, BinBoost bisa dipakai untuk klasifikasi dengan lebih dari 2 kelas (strategi One-vs-Rest)
|
|
16
|
+
|
|
17
|
+
## Instalasi
|
|
18
|
+
```bash
|
|
19
|
+
pip install binboost
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Penggunaan Dasar untuk Klasifikasi Biner
|
|
23
|
+
```python
|
|
24
|
+
import numpy as np
|
|
25
|
+
from binboost import BinBoost
|
|
26
|
+
|
|
27
|
+
X = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]], dtype=float)
|
|
28
|
+
y = np.array([1, 0, 1, 0])
|
|
29
|
+
|
|
30
|
+
model = BinBoost(n_estimators=100, learning_rate=0.2, max_rule_length=4)
|
|
31
|
+
model.fit(X, y)
|
|
32
|
+
|
|
33
|
+
print(model.predict(X))
|
|
34
|
+
print(model.predict_proba(X))
|
|
35
|
+
print(model.rules_)
|
|
36
|
+
|
|
37
|
+
import pandas as pd
|
|
38
|
+
print(pd.DataFrame(model.rule_summary_))
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Penggunaan Multi-Kelas (>2 kelas)
|
|
42
|
+
Untuk label dengan lebih dari 2 kelas yang saling eksklusif, gunakan `OneVsRestBinBoost` — hyperparameter yang diteruskan persis sama dengan `BinBoost`:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from binboost.multiclass import OneVsRestBinBoost
|
|
46
|
+
|
|
47
|
+
model = OneVsRestBinBoost(
|
|
48
|
+
mode='multiclass',
|
|
49
|
+
n_estimators=100,
|
|
50
|
+
learning_rate=0.2,
|
|
51
|
+
max_rule_length=4,
|
|
52
|
+
lambda0=3.0,
|
|
53
|
+
)
|
|
54
|
+
model.fit(X, y) # y boleh berisi >2 kelas, mis. array string atau integer
|
|
55
|
+
|
|
56
|
+
print(model.predict(X))
|
|
57
|
+
print(model.predict_proba(X)) # dinormalisasi supaya tiap baris berjumlah 1
|
|
58
|
+
print(pd.DataFrame(model.rule_summary_)) # aturan per kelas, kolom 'kelas' menandai sub-model asalnya
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`mode='multilabel'` tersedia untuk kasus di mana satu sampel bisa punya lebih dari satu label positif sekaligus dimana probabilitas tidak dinormalisasi, tiap kelas diputuskan independen.
|
|
62
|
+
|
|
63
|
+
## Hyperparameter Utama
|
|
64
|
+
|
|
65
|
+
| Parameter | Bawaan | Keterangan |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| `n_estimators` | 100 | Jumlah iterasi boosting |
|
|
68
|
+
| `learning_rate` | 0.2 | Faktor penyusutan tiap aturan |
|
|
69
|
+
| `loss` | `'logistic'` | Fungsi loss: `'logistic'`, `'focal'`, `'poly'` |
|
|
70
|
+
| `max_rule_length` | 4 | Jumlah maksimum fitur dalam satu aturan |
|
|
71
|
+
| `operators` | `['AND','OR']` | Operator logika yang digunakan ubah `use_xor=True` untuk mengaktifkan XOR |
|
|
72
|
+
| `beam_width` | 5 | Lebar beam search |
|
|
73
|
+
| `binarize_strategy` | `'gradient'` | Strategi binarisasi: `'gradient'`, `'quantile'`, `'uniform'`, `'kmeans'` |
|
|
74
|
+
| `subsample` | 0.8 | Fraksi data per iterasi |
|
|
75
|
+
| `feature_selection_threshold` | 0.0 | Ambang batas persentil gain fitur untuk seleksi kandidat (0.0 = semua fitur) |
|
|
76
|
+
| `min_samples_rule` | 5 | Jumlah/fraksi minimum sampel yang harus memenuhi sebuah aturan |
|
|
77
|
+
| `lambda0` | 3.0 | Konstanta regularisasi Newton adaptif |
|
|
78
|
+
| `gamma` | 0.0 | Ambang minimum gain untuk menerima sebuah aturan (0.0 = tanpa pruning, nonaktif secara bawaan) |
|
|
79
|
+
|
|
80
|
+
Fitur negasi (NOT) aktif otomatis pada pencarian aturan dan bukan hyperparameter yang bisa diatur lewat `BinBoost()` — ini bagian tetap dari mekanisme beam search.
|
|
81
|
+
|
|
82
|
+
## Fitur yang Didukung
|
|
83
|
+
- Fitur biner (0/1): langsung diproses
|
|
84
|
+
- Fitur numerik (int/float): dibinarisasi otomatis per iterasi
|
|
85
|
+
- Fitur kategorikal 3+ kelas: wajib OneHotEncode terlebih dahulu
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from sklearn.preprocessing import OneHotEncoder
|
|
89
|
+
enc = OneHotEncoder(sparse_output=False, drop='first')
|
|
90
|
+
X_encoded = enc.fit_transform(X[['kolom_kategorikal']])
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
BinBoost secara otomatis mendeteksi kelompok fitur OneHotEncoding dan mencegah aturan yang tidak masuk akal seperti `(Warna_Merah AND Warna_Biru)`.
|
|
94
|
+
|
|
95
|
+
## Atribut Setelah Pelatihan
|
|
96
|
+
```python
|
|
97
|
+
model.rules_ # daftar teks aturan termasuk NOT jika ada
|
|
98
|
+
model.rule_weights_ # bobot dua sisi [w0, w1] tiap aturan (hasil Newton + regularisasi)
|
|
99
|
+
model.feature_importances_ # skor kepentingan fitur
|
|
100
|
+
model.train_score_ # loss per iterasi
|
|
101
|
+
model.rule_summary_ # ringkasan lengkap atau konversi ke DataFrame
|
|
102
|
+
model.n_rules_ # jumlah aturan aktif
|
|
103
|
+
model.feature_usage_ # frekuensi penggunaan tiap fitur
|
|
104
|
+
model.thresholds_ # riwayat threshold biner per fitur numerik, per iterasi
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Lisensi
|
|
108
|
+
MIT
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# binboost/binboost.py
|
|
1
2
|
import numpy as np
|
|
2
3
|
|
|
3
4
|
from .loss import get_loss, sigmoid
|
|
@@ -136,6 +137,7 @@ class BinBoost:
|
|
|
136
137
|
subsample=0.8,
|
|
137
138
|
min_samples_rule=5,
|
|
138
139
|
lambda0=3.0,
|
|
140
|
+
gamma=0.0,
|
|
139
141
|
binarize_strategy='gradient',
|
|
140
142
|
n_thresholds='auto',
|
|
141
143
|
n_iter_no_change=None,
|
|
@@ -159,6 +161,7 @@ class BinBoost:
|
|
|
159
161
|
self.subsample = subsample
|
|
160
162
|
self.min_samples_rule = min_samples_rule
|
|
161
163
|
self.lambda0 = lambda0
|
|
164
|
+
self.gamma = gamma
|
|
162
165
|
self.binarize_strategy = binarize_strategy
|
|
163
166
|
self.n_thresholds = n_thresholds
|
|
164
167
|
self.n_iter_no_change = n_iter_no_change
|
|
@@ -322,6 +325,7 @@ class BinBoost:
|
|
|
322
325
|
min_samples_rule=self.min_samples_rule,
|
|
323
326
|
rule_complexity_penalty=self.rule_complexity_penalty,
|
|
324
327
|
ohe_groups=self.ohe_groups_,
|
|
328
|
+
gamma=self.gamma,
|
|
325
329
|
)
|
|
326
330
|
|
|
327
331
|
if not self.warm_start or not hasattr(self, 'estimators_'):
|
|
@@ -438,16 +442,25 @@ class BinBoost:
|
|
|
438
442
|
skor_terbaik = youden
|
|
439
443
|
threshold_terbaik = t
|
|
440
444
|
return float(threshold_terbaik)
|
|
445
|
+
|
|
446
|
+
def _binarize_untuk_iterasi(self, X, iterasi_idx, numeric_cols):
|
|
447
|
+
X_bin = X.copy().astype(np.float64)
|
|
448
|
+
for col in numeric_cols:
|
|
449
|
+
t = self.thresholds_[col][iterasi_idx]
|
|
450
|
+
X_bin[:, col] = (X[:, col] > t).astype(np.float64)
|
|
451
|
+
return X_bin
|
|
441
452
|
|
|
442
453
|
def _decision_function(self, X):
|
|
443
|
-
# Hitung nilai F akhir untuk seluruh sampel menggunakan update dua sisi
|
|
444
454
|
self._check_is_fitted()
|
|
445
455
|
X, _ = self._validate_input(X)
|
|
446
456
|
F = np.zeros(X.shape[0])
|
|
447
457
|
numeric_cols = self._detect_numeric_cols(X)
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
458
|
+
for i, (rule, weights) in enumerate(zip(self.estimators_, self.rule_weights_)):
|
|
459
|
+
if self.binarize_strategy == 'gradient' and numeric_cols:
|
|
460
|
+
X_bin = self._binarize_untuk_iterasi(X, i, numeric_cols)
|
|
461
|
+
else:
|
|
462
|
+
dummy_grad = np.ones(X.shape[0])
|
|
463
|
+
X_bin, _ = self._binarizer.transform(X, dummy_grad, numeric_cols)
|
|
451
464
|
h = rule.evaluate(X_bin)
|
|
452
465
|
w0, w1 = weights[0], weights[1]
|
|
453
466
|
F += self.learning_rate * (w1 * h + w0 * (1.0 - h))
|
|
@@ -509,10 +522,13 @@ class BinBoost:
|
|
|
509
522
|
self._check_is_fitted()
|
|
510
523
|
X, _ = self._validate_input(X)
|
|
511
524
|
numeric_cols = self._detect_numeric_cols(X)
|
|
512
|
-
dummy_grad = np.ones(X.shape[0])
|
|
513
|
-
X_bin, _ = self._binarizer.transform(X, dummy_grad, numeric_cols)
|
|
514
525
|
F = np.zeros(X.shape[0])
|
|
515
|
-
for rule, weights in zip(self.estimators_, self.rule_weights_):
|
|
526
|
+
for i, (rule, weights) in enumerate(zip(self.estimators_, self.rule_weights_)):
|
|
527
|
+
if self.binarize_strategy == 'gradient' and numeric_cols:
|
|
528
|
+
X_bin = self._binarize_untuk_iterasi(X, i, numeric_cols)
|
|
529
|
+
else:
|
|
530
|
+
dummy_grad = np.ones(X.shape[0])
|
|
531
|
+
X_bin, _ = self._binarizer.transform(X, dummy_grad, numeric_cols)
|
|
516
532
|
h = rule.evaluate(X_bin)
|
|
517
533
|
w0, w1 = weights[0], weights[1]
|
|
518
534
|
F += self.learning_rate * (w1 * h + w0 * (1.0 - h))
|
|
@@ -533,7 +549,7 @@ class BinBoost:
|
|
|
533
549
|
def apply(self, X):
|
|
534
550
|
"""
|
|
535
551
|
Kembalikan nilai aktivasi setiap aturan untuk setiap sampel.
|
|
536
|
-
|
|
552
|
+
|
|
537
553
|
Kembalian
|
|
538
554
|
----------
|
|
539
555
|
ndarray of shape (n_samples, n_estimators_)
|
|
@@ -541,11 +557,16 @@ class BinBoost:
|
|
|
541
557
|
self._check_is_fitted()
|
|
542
558
|
X, _ = self._validate_input(X)
|
|
543
559
|
numeric_cols = self._detect_numeric_cols(X)
|
|
544
|
-
dummy_grad = np.ones(X.shape[0])
|
|
545
|
-
X_bin, _ = self._binarizer.transform(X, dummy_grad, numeric_cols)
|
|
546
560
|
results = []
|
|
547
|
-
|
|
548
|
-
|
|
561
|
+
|
|
562
|
+
for i, rule in enumerate(self.estimators_):
|
|
563
|
+
if self.binarize_strategy == 'gradient' and numeric_cols:
|
|
564
|
+
X_bin = self._binarize_untuk_iterasi(X, i, numeric_cols)
|
|
565
|
+
else:
|
|
566
|
+
dummy_grad = np.ones(X.shape[0])
|
|
567
|
+
X_bin, _ = self._binarizer.transform(X, dummy_grad, numeric_cols)
|
|
568
|
+
results.append(rule.evaluate(X_bin))
|
|
569
|
+
|
|
549
570
|
return np.column_stack(results)
|
|
550
571
|
|
|
551
572
|
def get_params(self, deep=True):
|
|
@@ -571,7 +592,8 @@ class BinBoost:
|
|
|
571
592
|
'beam_width': self.beam_width,
|
|
572
593
|
'subsample': self.subsample,
|
|
573
594
|
'min_samples_rule': self.min_samples_rule,
|
|
574
|
-
'lambda0': self.lambda0,
|
|
595
|
+
'lambda0': self.lambda0,
|
|
596
|
+
'gamma': self.gamma,
|
|
575
597
|
'binarize_strategy': self.binarize_strategy,
|
|
576
598
|
'n_thresholds': self.n_thresholds,
|
|
577
599
|
'n_iter_no_change': self.n_iter_no_change,
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
# multiclass.py
|
|
1
|
+
# binboost/multiclass.py
|
|
2
2
|
import numpy as np
|
|
3
|
-
from binboost import BinBoost
|
|
3
|
+
from .binboost import BinBoost
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
class
|
|
6
|
+
class OneVsRestBinBoost:
|
|
7
|
+
"""
|
|
8
|
+
Ekstensi BinBoost untuk klasifikasi multi-kelas (>2 kelas) lewat strategi
|
|
9
|
+
One-vs-Rest, mirip pola sklearn.multiclass.OneVsRestClassifier.
|
|
10
|
+
Untuk 2 kelas, gunakan langsung BinBoost.
|
|
11
|
+
"""
|
|
12
|
+
|
|
7
13
|
def __init__(self, mode='multiclass', **binboost_params):
|
|
8
14
|
self.mode = mode
|
|
9
15
|
self.binboost_params = binboost_params
|
|
@@ -15,7 +21,6 @@ class BinBoostOvR:
|
|
|
15
21
|
self.n_classes_ = len(self.classes_)
|
|
16
22
|
if self.n_classes_ < 2:
|
|
17
23
|
raise ValueError("Minimal harus ada 2 kelas berbeda pada label y.")
|
|
18
|
-
|
|
19
24
|
self.estimators_ovr_ = []
|
|
20
25
|
for kelas in self.classes_:
|
|
21
26
|
y_bin = (y == kelas).astype(np.float64)
|
|
@@ -30,9 +35,7 @@ class BinBoostOvR:
|
|
|
30
35
|
def predict_proba(self, X):
|
|
31
36
|
raw = self._raw_scores(X)
|
|
32
37
|
if self.mode == 'multilabel':
|
|
33
|
-
# Tidak dinormalisasi — tiap kelas independen
|
|
34
38
|
return raw
|
|
35
|
-
# mode='multiclass' — normalisasi supaya tiap baris berjumlah 1
|
|
36
39
|
total = raw.sum(axis=1, keepdims=True)
|
|
37
40
|
semua_nol = (total.flatten() <= 1e-10)
|
|
38
41
|
total_aman = np.where(total <= 1e-10, 1.0, total)
|
|
@@ -43,17 +46,14 @@ class BinBoostOvR:
|
|
|
43
46
|
|
|
44
47
|
def predict(self, X):
|
|
45
48
|
if self.mode == 'multilabel':
|
|
46
|
-
|
|
47
|
-
preds = np.column_stack([m.predict(X) for m in self.estimators_ovr_])
|
|
48
|
-
return preds
|
|
49
|
+
return np.column_stack([m.predict(X) for m in self.estimators_ovr_])
|
|
49
50
|
probs = self.predict_proba(X)
|
|
50
51
|
idx = np.argmax(probs, axis=1)
|
|
51
52
|
return self.classes_[idx]
|
|
52
53
|
|
|
53
54
|
def score(self, X, y):
|
|
54
55
|
y = np.asarray(y)
|
|
55
|
-
|
|
56
|
-
return np.mean(preds == y)
|
|
56
|
+
return np.mean(self.predict(X) == y)
|
|
57
57
|
|
|
58
58
|
@property
|
|
59
59
|
def rule_summary_(self):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# rule.py
|
|
1
|
+
# binboost/rule.py
|
|
2
2
|
import numpy as np
|
|
3
3
|
|
|
4
4
|
class Rule:
|
|
@@ -6,8 +6,7 @@ class Rule:
|
|
|
6
6
|
def __init__(self, features, operators, weight, negations=None, feature_names=None):
|
|
7
7
|
self.features = features
|
|
8
8
|
self.operators = operators
|
|
9
|
-
self.
|
|
10
|
-
# Daftar boolean sepanjang features: True berarti fitur itu dipakai dalam bentuk negasi (NOT)
|
|
9
|
+
self._search_weight = weight
|
|
11
10
|
self.negations = negations if negations is not None else [False] * len(features)
|
|
12
11
|
self.feature_names = feature_names
|
|
13
12
|
|
|
@@ -45,13 +44,13 @@ class Rule:
|
|
|
45
44
|
return expr
|
|
46
45
|
|
|
47
46
|
def __repr__(self):
|
|
48
|
-
return f"Rule({self.to_string()}
|
|
47
|
+
return f"Rule({self.to_string()})"
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
class BeamSearchRuleFinder:
|
|
52
51
|
def __init__(self, operators, max_rule_length, beam_width,
|
|
53
52
|
feature_selection_threshold, min_samples_rule,
|
|
54
|
-
rule_complexity_penalty, ohe_groups=None, allow_negation=True):
|
|
53
|
+
rule_complexity_penalty, ohe_groups=None, allow_negation=True, gamma=0.0):
|
|
55
54
|
self.operators = operators
|
|
56
55
|
self.max_rule_length = max_rule_length
|
|
57
56
|
self.beam_width = beam_width
|
|
@@ -59,7 +58,8 @@ class BeamSearchRuleFinder:
|
|
|
59
58
|
self.min_samples_rule = min_samples_rule
|
|
60
59
|
self.rule_complexity_penalty = rule_complexity_penalty
|
|
61
60
|
self.ohe_groups = ohe_groups
|
|
62
|
-
self.allow_negation = allow_negation
|
|
61
|
+
self.allow_negation = allow_negation
|
|
62
|
+
self.gamma = gamma
|
|
63
63
|
|
|
64
64
|
self._feature_to_group = {}
|
|
65
65
|
if ohe_groups is not None:
|
|
@@ -94,6 +94,7 @@ class BeamSearchRuleFinder:
|
|
|
94
94
|
def find_best_rule(self, X_bin, gradients):
|
|
95
95
|
n_samples, n_features = X_bin.shape
|
|
96
96
|
min_s = self._min_samples_int(n_samples)
|
|
97
|
+
baseline = float(np.dot(gradients, gradients))
|
|
97
98
|
if hasattr(self, 'forced_candidate_features') and self.forced_candidate_features is not None:
|
|
98
99
|
candidate_features = self.forced_candidate_features
|
|
99
100
|
else:
|
|
@@ -121,7 +122,8 @@ class BeamSearchRuleFinder:
|
|
|
121
122
|
return None
|
|
122
123
|
|
|
123
124
|
w_init, scores_init, w_valid = self._compute_scores_batch(H_init, gradients)
|
|
124
|
-
|
|
125
|
+
gain_init = baseline - scores_init
|
|
126
|
+
valid_mask = valid_init & w_valid & (gain_init >= self.gamma)
|
|
125
127
|
if not valid_mask.any():
|
|
126
128
|
return None
|
|
127
129
|
|
|
@@ -182,7 +184,8 @@ class BeamSearchRuleFinder:
|
|
|
182
184
|
continue
|
|
183
185
|
|
|
184
186
|
w_new, scores_new, w_valid_new = self._compute_scores_batch(H_new, gradients)
|
|
185
|
-
|
|
187
|
+
gain_new = baseline - scores_new
|
|
188
|
+
valid_combined = valid_sup & w_valid_new & (gain_new >= self.gamma)
|
|
186
189
|
|
|
187
190
|
for j, cf_int in enumerate(expandable):
|
|
188
191
|
if not valid_combined[j]:
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: binboost
|
|
3
|
+
Version: 0.2.3
|
|
4
|
+
Summary: Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner
|
|
5
|
+
Author: Rangga Wahyu Pratama
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: gradient boosting,logical rules,binary features,interpretable machine learning
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Requires-Python: >=3.8
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: numpy>=1.21.0
|
|
17
|
+
Requires-Dist: pandas>=1.3.0
|
|
18
|
+
Dynamic: author
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
|
|
22
|
+
# BinBoost
|
|
23
|
+
|
|
24
|
+
**Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner, dengan Regularisasi Newton-Hessian dan Dukungan Multi-Kelas**
|
|
25
|
+
|
|
26
|
+
BinBoost adalah algoritma klasifikasi gradient boosting yang membangun ensemble aturan logika murni (AND, OR, XOR, termasuk negasi NOT) dengan binarisasi fitur numerik adaptif berbasis gradien pada setiap iterasi boosting. Bobot tiap aturan dihitung dengan pendekatan Newton (memakai Hessian per fungsi loss) dan regularisasi adaptif berbasis dukungan sampel & kompleksitas aturan. Setiap weak learner berupa aturan yang dapat dibaca langsung oleh manusia tanpa memerlukan alat bantu penjelasan pasca-pelatihan.
|
|
27
|
+
|
|
28
|
+
## Kebaruan Utama
|
|
29
|
+
- **Binarisasi adaptif berbasis gradien**: nilai ambang batas fitur numerik dicari per iterasi untuk memaksimalkan korelasi dengan gradien saat ini
|
|
30
|
+
- **Ensemble aturan logika murni**: tidak ada pohon keputusan, setiap weak learner adalah aturan seperti: `(A AND B)`, `(C OR D)`, atau `(A AND NOT B)`
|
|
31
|
+
- **Youden J**: Penggunaan indeks Youden J sebagai `threshold='auto'` bawaan untuk menentukan titik potong prediksi, bukan fixed di 0.5 serta mengoptimalkan sensitivity + specificity pada data training, cocok untuk kasus kelas tidak seimbang
|
|
32
|
+
- **Fitur ternegasi (NOT)**: pencarian aturan otomatis mempertimbangkan dua polaritas (asli dan negasi) untuk tiap kandidat fitur
|
|
33
|
+
- **Bobot aturan berbasis Newton (Hessian)**: bobot dua sisi tiap aturan dihitung dengan `w = G/(H+λ)`, memakai turunan kedua (Hessian) yang sesuai dengan fungsi loss yang dipilih (logistic, focal, atau poly), bukan sekadar rata-rata gradien
|
|
34
|
+
- **Regularisasi adaptif**: `λ` menyesuaikan otomatis terhadap jumlah sampel dan panjang aturan, sehingga aturan dengan cakupan kecil/kompleks ditahan bobotnya secara proporsional
|
|
35
|
+
- **Minimum-gain pruning (`gamma`)**: aturan dengan kontribusi terlalu kecil bisa ditolak sebelum masuk ensemble, membantu mencegah overfitting pada aturan yang terlalu spesifik
|
|
36
|
+
- **Dukungan multi-kelas**: lewat `binboost.multiclass.OneVsRestBinBoost`, BinBoost bisa dipakai untuk klasifikasi dengan lebih dari 2 kelas (strategi One-vs-Rest)
|
|
37
|
+
|
|
38
|
+
## Instalasi
|
|
39
|
+
```bash
|
|
40
|
+
pip install binboost
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Penggunaan Dasar untuk Klasifikasi Biner
|
|
44
|
+
```python
|
|
45
|
+
import numpy as np
|
|
46
|
+
from binboost import BinBoost
|
|
47
|
+
|
|
48
|
+
X = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]], dtype=float)
|
|
49
|
+
y = np.array([1, 0, 1, 0])
|
|
50
|
+
|
|
51
|
+
model = BinBoost(n_estimators=100, learning_rate=0.2, max_rule_length=4)
|
|
52
|
+
model.fit(X, y)
|
|
53
|
+
|
|
54
|
+
print(model.predict(X))
|
|
55
|
+
print(model.predict_proba(X))
|
|
56
|
+
print(model.rules_)
|
|
57
|
+
|
|
58
|
+
import pandas as pd
|
|
59
|
+
print(pd.DataFrame(model.rule_summary_))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Penggunaan Multi-Kelas (>2 kelas)
|
|
63
|
+
Untuk label dengan lebih dari 2 kelas yang saling eksklusif, gunakan `OneVsRestBinBoost` — hyperparameter yang diteruskan persis sama dengan `BinBoost`:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from binboost.multiclass import OneVsRestBinBoost
|
|
67
|
+
|
|
68
|
+
model = OneVsRestBinBoost(
|
|
69
|
+
mode='multiclass',
|
|
70
|
+
n_estimators=100,
|
|
71
|
+
learning_rate=0.2,
|
|
72
|
+
max_rule_length=4,
|
|
73
|
+
lambda0=3.0,
|
|
74
|
+
)
|
|
75
|
+
model.fit(X, y) # y boleh berisi >2 kelas, mis. array string atau integer
|
|
76
|
+
|
|
77
|
+
print(model.predict(X))
|
|
78
|
+
print(model.predict_proba(X)) # dinormalisasi supaya tiap baris berjumlah 1
|
|
79
|
+
print(pd.DataFrame(model.rule_summary_)) # aturan per kelas, kolom 'kelas' menandai sub-model asalnya
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`mode='multilabel'` tersedia untuk kasus di mana satu sampel bisa punya lebih dari satu label positif sekaligus dimana probabilitas tidak dinormalisasi, tiap kelas diputuskan independen.
|
|
83
|
+
|
|
84
|
+
## Hyperparameter Utama
|
|
85
|
+
|
|
86
|
+
| Parameter | Bawaan | Keterangan |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| `n_estimators` | 100 | Jumlah iterasi boosting |
|
|
89
|
+
| `learning_rate` | 0.2 | Faktor penyusutan tiap aturan |
|
|
90
|
+
| `loss` | `'logistic'` | Fungsi loss: `'logistic'`, `'focal'`, `'poly'` |
|
|
91
|
+
| `max_rule_length` | 4 | Jumlah maksimum fitur dalam satu aturan |
|
|
92
|
+
| `operators` | `['AND','OR']` | Operator logika yang digunakan ubah `use_xor=True` untuk mengaktifkan XOR |
|
|
93
|
+
| `beam_width` | 5 | Lebar beam search |
|
|
94
|
+
| `binarize_strategy` | `'gradient'` | Strategi binarisasi: `'gradient'`, `'quantile'`, `'uniform'`, `'kmeans'` |
|
|
95
|
+
| `subsample` | 0.8 | Fraksi data per iterasi |
|
|
96
|
+
| `feature_selection_threshold` | 0.0 | Ambang batas persentil gain fitur untuk seleksi kandidat (0.0 = semua fitur) |
|
|
97
|
+
| `min_samples_rule` | 5 | Jumlah/fraksi minimum sampel yang harus memenuhi sebuah aturan |
|
|
98
|
+
| `lambda0` | 3.0 | Konstanta regularisasi Newton adaptif |
|
|
99
|
+
| `gamma` | 0.0 | Ambang minimum gain untuk menerima sebuah aturan (0.0 = tanpa pruning, nonaktif secara bawaan) |
|
|
100
|
+
|
|
101
|
+
Fitur negasi (NOT) aktif otomatis pada pencarian aturan dan bukan hyperparameter yang bisa diatur lewat `BinBoost()` — ini bagian tetap dari mekanisme beam search.
|
|
102
|
+
|
|
103
|
+
## Fitur yang Didukung
|
|
104
|
+
- Fitur biner (0/1): langsung diproses
|
|
105
|
+
- Fitur numerik (int/float): dibinarisasi otomatis per iterasi
|
|
106
|
+
- Fitur kategorikal 3+ kelas: wajib OneHotEncode terlebih dahulu
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from sklearn.preprocessing import OneHotEncoder
|
|
110
|
+
enc = OneHotEncoder(sparse_output=False, drop='first')
|
|
111
|
+
X_encoded = enc.fit_transform(X[['kolom_kategorikal']])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
BinBoost secara otomatis mendeteksi kelompok fitur OneHotEncoding dan mencegah aturan yang tidak masuk akal seperti `(Warna_Merah AND Warna_Biru)`.
|
|
115
|
+
|
|
116
|
+
## Atribut Setelah Pelatihan
|
|
117
|
+
```python
|
|
118
|
+
model.rules_ # daftar teks aturan termasuk NOT jika ada
|
|
119
|
+
model.rule_weights_ # bobot dua sisi [w0, w1] tiap aturan (hasil Newton + regularisasi)
|
|
120
|
+
model.feature_importances_ # skor kepentingan fitur
|
|
121
|
+
model.train_score_ # loss per iterasi
|
|
122
|
+
model.rule_summary_ # ringkasan lengkap atau konversi ke DataFrame
|
|
123
|
+
model.n_rules_ # jumlah aturan aktif
|
|
124
|
+
model.feature_usage_ # frekuensi penggunaan tiap fitur
|
|
125
|
+
model.thresholds_ # riwayat threshold biner per fitur numerik, per iterasi
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Lisensi
|
|
129
|
+
MIT
|
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name="binboost",
|
|
5
|
-
version="0.2.
|
|
5
|
+
version="0.2.3",
|
|
6
6
|
author="Rangga Wahyu Pratama",
|
|
7
7
|
description="Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner",
|
|
8
8
|
long_description=open("README.md", encoding="utf-8").read(),
|
binboost-0.2.2/PKG-INFO
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: binboost
|
|
3
|
-
Version: 0.2.2
|
|
4
|
-
Summary: Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner
|
|
5
|
-
Author: Rangga Wahyu Pratama
|
|
6
|
-
License: MIT
|
|
7
|
-
Keywords: gradient boosting,logical rules,binary features,interpretable machine learning
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: Intended Audience :: Science/Research
|
|
12
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
-
Requires-Python: >=3.8
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: numpy>=1.21.0
|
|
17
|
-
Requires-Dist: pandas>=1.3.0
|
|
18
|
-
Dynamic: author
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
Dynamic: requires-python
|
|
21
|
-
|
|
22
|
-
# BinBoost
|
|
23
|
-
|
|
24
|
-
**Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner**
|
|
25
|
-
|
|
26
|
-
BinBoost adalah algoritma klasifikasi gradient boosting yang membangun ensemble aturan logika murni (AND, OR, XOR) dengan binarisasi fitur numerik adaptif berbasis gradien pada setiap iterasi boosting. Setiap weak learner berupa aturan yang dapat dibaca langsung oleh manusia tanpa memerlukan alat bantu penjelasan pasca-pelatihan.
|
|
27
|
-
|
|
28
|
-
## Kebaruan Utama
|
|
29
|
-
|
|
30
|
-
- **Binarisasi adaptif berbasis gradien**: nilai ambang batas fitur numerik dicari per iterasi untuk memaksimalkan korelasi dengan gradien saat ini
|
|
31
|
-
- **Ensemble aturan logika murni**: tidak ada pohon keputusan, setiap weak learner adalah aturan seperti `(A AND B)` atau `(C OR D)`
|
|
32
|
-
|
|
33
|
-
## Instalasi
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
pip install binboost
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Penggunaan Dasar
|
|
40
|
-
|
|
41
|
-
```python
|
|
42
|
-
import numpy as np
|
|
43
|
-
from binboost import BinBoost
|
|
44
|
-
|
|
45
|
-
X = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]], dtype=float)
|
|
46
|
-
y = np.array([1, 0, 1, 0])
|
|
47
|
-
|
|
48
|
-
model = BinBoost(n_estimators=50, learning_rate=0.1, max_rule_length=2)
|
|
49
|
-
model.fit(X, y)
|
|
50
|
-
|
|
51
|
-
print(model.predict(X))
|
|
52
|
-
print(model.predict_proba(X))
|
|
53
|
-
print(model.rules_)
|
|
54
|
-
|
|
55
|
-
import pandas as pd
|
|
56
|
-
print(pd.DataFrame(model.rule_summary_))
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Hyperparameter Utama
|
|
60
|
-
|
|
61
|
-
| Parameter | Bawaan | Keterangan |
|
|
62
|
-
|---|---|---|
|
|
63
|
-
| `n_estimators` | 100 | Jumlah iterasi boosting |
|
|
64
|
-
| `learning_rate` | 0.1 | Faktor penyusutan tiap aturan |
|
|
65
|
-
| `loss` | `'logistic'` | Fungsi loss: `'logistic'`, `'focal'`, `'poly'` |
|
|
66
|
-
| `max_rule_length` | 2 | Jumlah maksimum fitur dalam satu aturan |
|
|
67
|
-
| `operators` | `['AND','OR']` | Operator logika yang digunakan |
|
|
68
|
-
| `beam_width` | 5 | Lebar beam search |
|
|
69
|
-
| `binarize_strategy` | `'gradient'` | Strategi binarisasi: `'gradient'`, `'quantile'`, `'uniform'`, `'kmeans'` |
|
|
70
|
-
| `subsample` | 0.8 | Fraksi data per iterasi |
|
|
71
|
-
| `feature_selection_threshold` | 0.01 | Ambang batas seleksi fitur berbasis gradien |
|
|
72
|
-
|
|
73
|
-
## Fitur yang Didukung
|
|
74
|
-
|
|
75
|
-
- Fitur biner (0/1): langsung diproses
|
|
76
|
-
- Fitur numerik (int/float): dibinarisasi otomatis
|
|
77
|
-
- Fitur kategorikal 3+ kelas: wajib OneHotEncode terlebih dahulu
|
|
78
|
-
|
|
79
|
-
```python
|
|
80
|
-
from sklearn.preprocessing import OneHotEncoder
|
|
81
|
-
enc = OneHotEncoder(sparse_output=False, drop='first')
|
|
82
|
-
X_encoded = enc.fit_transform(X[['kolom_kategorikal']])
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
BinBoost secara otomatis mendeteksi kelompok fitur OneHotEncoding dan mencegah aturan yang tidak masuk akal seperti `(Warna_Merah AND Warna_Biru)`.
|
|
86
|
-
|
|
87
|
-
## Atribut Setelah Pelatihan
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
model.rules_ # daftar teks aturan
|
|
91
|
-
model.rule_weights_ # bobot setiap aturan
|
|
92
|
-
model.feature_importances_ # skor kepentingan fitur
|
|
93
|
-
model.train_score_ # loss per iterasi
|
|
94
|
-
model.rule_summary_ # ringkasan lengkap atau konversi ke DataFrame
|
|
95
|
-
model.n_rules_ # jumlah aturan aktif
|
|
96
|
-
model.feature_usage_ # frekuensi penggunaan tiap fitur
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Lisensi
|
|
100
|
-
|
|
101
|
-
MIT
|
binboost-0.2.2/README.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# BinBoost
|
|
2
|
-
|
|
3
|
-
**Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner**
|
|
4
|
-
|
|
5
|
-
BinBoost adalah algoritma klasifikasi gradient boosting yang membangun ensemble aturan logika murni (AND, OR, XOR) dengan binarisasi fitur numerik adaptif berbasis gradien pada setiap iterasi boosting. Setiap weak learner berupa aturan yang dapat dibaca langsung oleh manusia tanpa memerlukan alat bantu penjelasan pasca-pelatihan.
|
|
6
|
-
|
|
7
|
-
## Kebaruan Utama
|
|
8
|
-
|
|
9
|
-
- **Binarisasi adaptif berbasis gradien**: nilai ambang batas fitur numerik dicari per iterasi untuk memaksimalkan korelasi dengan gradien saat ini
|
|
10
|
-
- **Ensemble aturan logika murni**: tidak ada pohon keputusan, setiap weak learner adalah aturan seperti `(A AND B)` atau `(C OR D)`
|
|
11
|
-
|
|
12
|
-
## Instalasi
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
pip install binboost
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Penggunaan Dasar
|
|
19
|
-
|
|
20
|
-
```python
|
|
21
|
-
import numpy as np
|
|
22
|
-
from binboost import BinBoost
|
|
23
|
-
|
|
24
|
-
X = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]], dtype=float)
|
|
25
|
-
y = np.array([1, 0, 1, 0])
|
|
26
|
-
|
|
27
|
-
model = BinBoost(n_estimators=50, learning_rate=0.1, max_rule_length=2)
|
|
28
|
-
model.fit(X, y)
|
|
29
|
-
|
|
30
|
-
print(model.predict(X))
|
|
31
|
-
print(model.predict_proba(X))
|
|
32
|
-
print(model.rules_)
|
|
33
|
-
|
|
34
|
-
import pandas as pd
|
|
35
|
-
print(pd.DataFrame(model.rule_summary_))
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Hyperparameter Utama
|
|
39
|
-
|
|
40
|
-
| Parameter | Bawaan | Keterangan |
|
|
41
|
-
|---|---|---|
|
|
42
|
-
| `n_estimators` | 100 | Jumlah iterasi boosting |
|
|
43
|
-
| `learning_rate` | 0.1 | Faktor penyusutan tiap aturan |
|
|
44
|
-
| `loss` | `'logistic'` | Fungsi loss: `'logistic'`, `'focal'`, `'poly'` |
|
|
45
|
-
| `max_rule_length` | 2 | Jumlah maksimum fitur dalam satu aturan |
|
|
46
|
-
| `operators` | `['AND','OR']` | Operator logika yang digunakan |
|
|
47
|
-
| `beam_width` | 5 | Lebar beam search |
|
|
48
|
-
| `binarize_strategy` | `'gradient'` | Strategi binarisasi: `'gradient'`, `'quantile'`, `'uniform'`, `'kmeans'` |
|
|
49
|
-
| `subsample` | 0.8 | Fraksi data per iterasi |
|
|
50
|
-
| `feature_selection_threshold` | 0.01 | Ambang batas seleksi fitur berbasis gradien |
|
|
51
|
-
|
|
52
|
-
## Fitur yang Didukung
|
|
53
|
-
|
|
54
|
-
- Fitur biner (0/1): langsung diproses
|
|
55
|
-
- Fitur numerik (int/float): dibinarisasi otomatis
|
|
56
|
-
- Fitur kategorikal 3+ kelas: wajib OneHotEncode terlebih dahulu
|
|
57
|
-
|
|
58
|
-
```python
|
|
59
|
-
from sklearn.preprocessing import OneHotEncoder
|
|
60
|
-
enc = OneHotEncoder(sparse_output=False, drop='first')
|
|
61
|
-
X_encoded = enc.fit_transform(X[['kolom_kategorikal']])
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
BinBoost secara otomatis mendeteksi kelompok fitur OneHotEncoding dan mencegah aturan yang tidak masuk akal seperti `(Warna_Merah AND Warna_Biru)`.
|
|
65
|
-
|
|
66
|
-
## Atribut Setelah Pelatihan
|
|
67
|
-
|
|
68
|
-
```python
|
|
69
|
-
model.rules_ # daftar teks aturan
|
|
70
|
-
model.rule_weights_ # bobot setiap aturan
|
|
71
|
-
model.feature_importances_ # skor kepentingan fitur
|
|
72
|
-
model.train_score_ # loss per iterasi
|
|
73
|
-
model.rule_summary_ # ringkasan lengkap atau konversi ke DataFrame
|
|
74
|
-
model.n_rules_ # jumlah aturan aktif
|
|
75
|
-
model.feature_usage_ # frekuensi penggunaan tiap fitur
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## Lisensi
|
|
79
|
-
|
|
80
|
-
MIT
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: binboost
|
|
3
|
-
Version: 0.2.2
|
|
4
|
-
Summary: Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner
|
|
5
|
-
Author: Rangga Wahyu Pratama
|
|
6
|
-
License: MIT
|
|
7
|
-
Keywords: gradient boosting,logical rules,binary features,interpretable machine learning
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
11
|
-
Classifier: Intended Audience :: Science/Research
|
|
12
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
-
Requires-Python: >=3.8
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: numpy>=1.21.0
|
|
17
|
-
Requires-Dist: pandas>=1.3.0
|
|
18
|
-
Dynamic: author
|
|
19
|
-
Dynamic: license-file
|
|
20
|
-
Dynamic: requires-python
|
|
21
|
-
|
|
22
|
-
# BinBoost
|
|
23
|
-
|
|
24
|
-
**Gradient Boosting Berbasis Aturan Logika Adaptif untuk Fitur Biner**
|
|
25
|
-
|
|
26
|
-
BinBoost adalah algoritma klasifikasi gradient boosting yang membangun ensemble aturan logika murni (AND, OR, XOR) dengan binarisasi fitur numerik adaptif berbasis gradien pada setiap iterasi boosting. Setiap weak learner berupa aturan yang dapat dibaca langsung oleh manusia tanpa memerlukan alat bantu penjelasan pasca-pelatihan.
|
|
27
|
-
|
|
28
|
-
## Kebaruan Utama
|
|
29
|
-
|
|
30
|
-
- **Binarisasi adaptif berbasis gradien**: nilai ambang batas fitur numerik dicari per iterasi untuk memaksimalkan korelasi dengan gradien saat ini
|
|
31
|
-
- **Ensemble aturan logika murni**: tidak ada pohon keputusan, setiap weak learner adalah aturan seperti `(A AND B)` atau `(C OR D)`
|
|
32
|
-
|
|
33
|
-
## Instalasi
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
pip install binboost
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Penggunaan Dasar
|
|
40
|
-
|
|
41
|
-
```python
|
|
42
|
-
import numpy as np
|
|
43
|
-
from binboost import BinBoost
|
|
44
|
-
|
|
45
|
-
X = np.array([[1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 0, 1]], dtype=float)
|
|
46
|
-
y = np.array([1, 0, 1, 0])
|
|
47
|
-
|
|
48
|
-
model = BinBoost(n_estimators=50, learning_rate=0.1, max_rule_length=2)
|
|
49
|
-
model.fit(X, y)
|
|
50
|
-
|
|
51
|
-
print(model.predict(X))
|
|
52
|
-
print(model.predict_proba(X))
|
|
53
|
-
print(model.rules_)
|
|
54
|
-
|
|
55
|
-
import pandas as pd
|
|
56
|
-
print(pd.DataFrame(model.rule_summary_))
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Hyperparameter Utama
|
|
60
|
-
|
|
61
|
-
| Parameter | Bawaan | Keterangan |
|
|
62
|
-
|---|---|---|
|
|
63
|
-
| `n_estimators` | 100 | Jumlah iterasi boosting |
|
|
64
|
-
| `learning_rate` | 0.1 | Faktor penyusutan tiap aturan |
|
|
65
|
-
| `loss` | `'logistic'` | Fungsi loss: `'logistic'`, `'focal'`, `'poly'` |
|
|
66
|
-
| `max_rule_length` | 2 | Jumlah maksimum fitur dalam satu aturan |
|
|
67
|
-
| `operators` | `['AND','OR']` | Operator logika yang digunakan |
|
|
68
|
-
| `beam_width` | 5 | Lebar beam search |
|
|
69
|
-
| `binarize_strategy` | `'gradient'` | Strategi binarisasi: `'gradient'`, `'quantile'`, `'uniform'`, `'kmeans'` |
|
|
70
|
-
| `subsample` | 0.8 | Fraksi data per iterasi |
|
|
71
|
-
| `feature_selection_threshold` | 0.01 | Ambang batas seleksi fitur berbasis gradien |
|
|
72
|
-
|
|
73
|
-
## Fitur yang Didukung
|
|
74
|
-
|
|
75
|
-
- Fitur biner (0/1): langsung diproses
|
|
76
|
-
- Fitur numerik (int/float): dibinarisasi otomatis
|
|
77
|
-
- Fitur kategorikal 3+ kelas: wajib OneHotEncode terlebih dahulu
|
|
78
|
-
|
|
79
|
-
```python
|
|
80
|
-
from sklearn.preprocessing import OneHotEncoder
|
|
81
|
-
enc = OneHotEncoder(sparse_output=False, drop='first')
|
|
82
|
-
X_encoded = enc.fit_transform(X[['kolom_kategorikal']])
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
BinBoost secara otomatis mendeteksi kelompok fitur OneHotEncoding dan mencegah aturan yang tidak masuk akal seperti `(Warna_Merah AND Warna_Biru)`.
|
|
86
|
-
|
|
87
|
-
## Atribut Setelah Pelatihan
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
model.rules_ # daftar teks aturan
|
|
91
|
-
model.rule_weights_ # bobot setiap aturan
|
|
92
|
-
model.feature_importances_ # skor kepentingan fitur
|
|
93
|
-
model.train_score_ # loss per iterasi
|
|
94
|
-
model.rule_summary_ # ringkasan lengkap atau konversi ke DataFrame
|
|
95
|
-
model.n_rules_ # jumlah aturan aktif
|
|
96
|
-
model.feature_usage_ # frekuensi penggunaan tiap fitur
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Lisensi
|
|
100
|
-
|
|
101
|
-
MIT
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|