forked from Koukyosyumei/AIJack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_secureboost.py
More file actions
93 lines (81 loc) · 2.01 KB
/
test_secureboost.py
File metadata and controls
93 lines (81 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def test_secureboostclassifier():
import numpy as np # noqa: F401
from aijack.collaborative.secureboost import ( # noqa: F401
Party,
SecureBoostClassifier,
)
min_leaf = 1
depth = 3
learning_rate = 0.4
boosting_rounds = 2
lam = 1.0
gamma = 0.0
eps = 1.0
min_child_weight = -1 * float("inf")
subsample_cols = 1.0
clf = SecureBoostClassifier(
subsample_cols,
min_child_weight,
depth,
min_leaf,
learning_rate,
boosting_rounds,
lam,
gamma,
eps,
)
x1 = [12, 32, 15, 24, 20, 25, 17, 16]
x1 = [[x] for x in x1]
x2 = [1, 1, 0, 0, 1, 1, 0, 1]
x2 = [[x] for x in x2]
y = [1, 0, 1, 0, 1, 1, 0, 1]
p1 = Party(x1, [0], 0, min_leaf, subsample_cols)
p2 = Party(x2, [1], 1, min_leaf, subsample_cols)
parties = [p1, p2]
base_pred = clf.get_init_pred(y)
assert np.allclose(base_pred, [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
assert np.allclose(
clf.get_grad(base_pred, y),
[
-0.26894,
0.73106,
-0.26894,
0.73106,
-0.26894,
-0.26894,
0.73106,
-0.26894,
],
)
assert np.allclose(
clf.get_hess(base_pred, y),
[0.19661, 0.19661, 0.19661, 0.19661, 0.19661, 0.19661, 0.19661, 0.19661],
)
clf.fit(parties, y)
X = [[12, 1], [32, 1], [15, 0], [24, 0], [20, 1], [25, 1], [17, 0], [16, 1]]
assert np.allclose(
clf.predict_raw(X),
[
1.38379341,
0.53207456,
1.38379341,
0.22896408,
1.29495549,
1.29495549,
0.22896408,
1.38379341,
],
)
assert np.allclose(
clf.predict_proba(X),
[
0.79959955,
0.62996684,
0.79959955,
0.55699226,
0.78498478,
0.78498478,
0.55699226,
0.79959955,
],
)