This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_nnet.py
54 lines (39 loc) · 1.64 KB
/
test_nnet.py
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
"""
Testing all the library
"""
from __future__ import division, print_function
from sklearn.linear_model.logistic import LogisticRegression
from cmsuml import nnet
from sklearn.datasets import make_blobs
from sklearn.metrics import roc_auc_score
__author__ = 'Alex Rogozhnikov'
import numpy
def test_nnet(n_samples=200, n_features=5, distance=0.5):
X, y = make_blobs(n_samples=n_samples, n_features=5,
centers=[numpy.ones(n_features) * distance, - numpy.ones(n_features) * distance])
nn_types = [
nnet.SimpleNeuralNetwork,
nnet.MultiLayerNetwork,
nnet.SoftmaxNeuralNetwork,
nnet.RBFNeuralNetwork,
nnet.PairwiseNeuralNetwork,
nnet.PairwiseSoftplusNeuralNetwork,
]
for loss in nnet.losses:
for NNType in nn_types:
for trainer in nnet.trainers:
nn = NNType(layers=[5], loss=loss, trainer=trainer, random_state=42)
nn.fit(X, y, stages=100, verbose=nnet.SILENT)
print(roc_auc_score(y, nn.predict_proba(X)[:, 1]), nn)
lr = LogisticRegression().fit(X, y)
print(lr, roc_auc_score(y, lr.predict_proba(X)[:, 1]))
assert 0 == 1
def test_oblivious(n_samples=200, n_features=5, distance=0.5):
# Since oblivious NN is very slow, it is tested separately
nn = nnet.ObliviousNeuralNetwork(layers=[3], trainer='irprop-')
X, y = make_blobs(n_samples=n_samples, n_features=5,
centers=[numpy.ones(n_features) * distance, - numpy.ones(n_features) * distance])
nn.fit(X, y, batch=100, verbose=10)
print(roc_auc_score(y, nn.predict_proba(X)[:, 1]), nn)
test_oblivious()
test_nnet()