Mercurial > hg > tvii
comparison tests/test_logistic_regression.py @ 28:77f68c241b37
[logistic regression] propagate
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 04 Sep 2017 11:53:23 -0700 |
parents | f34110e28a0a |
children | cf7584f0a29f |
comparison
equal
deleted
inserted
replaced
27:22218d90d33f | 28:77f68c241b37 |
---|---|
6 | 6 |
7 import numpy as np | 7 import numpy as np |
8 import os | 8 import os |
9 import unittest | 9 import unittest |
10 from tvii import logistic_regression | 10 from tvii import logistic_regression |
11 | |
11 | 12 |
12 class LogisticRegresionTests(unittest.TestCase): | 13 class LogisticRegresionTests(unittest.TestCase): |
13 | 14 |
14 def test_cost(self): | 15 def test_cost(self): |
15 """test cost function""" | 16 """test cost function""" |
21 | 22 |
22 expected_cost = 6.000064773192205 | 23 expected_cost = 6.000064773192205 |
23 cost = logistic_regression.cost_function(w, b, X, Y) | 24 cost = logistic_regression.cost_function(w, b, X, Y) |
24 assert abs(cost - expected_cost) < 1e-6 | 25 assert abs(cost - expected_cost) < 1e-6 |
25 | 26 |
27 def test_propagate(self): | |
28 """test canned logistic regression example""" | |
29 | |
30 # sample variables | |
31 w = np.array([[1],[2]]) | |
32 b = 2 | |
33 X = np.array([[1,2],[3,4]]) | |
34 Y = np.array([[1,0]]) | |
35 | |
36 # calculate gradient and cost | |
37 grads, cost = logistic_regression.propagate(w, b, X, Y) | |
38 | |
39 # compare to expected, | |
40 dw_expected = [[ 0.99993216], [ 1.99980262]] | |
41 db_expected = 0.499935230625 | |
42 cost_expected = 6.000064773192205 | |
43 | |
44 | |
26 if __name__ == '__main__': | 45 if __name__ == '__main__': |
27 unittest.main() | 46 unittest.main() |