annotate tests/test_logistic_regression.py @ 22:3713c6733990

[logistic regression] introduce illustrative test
author Jeff Hammel <k0scist@gmail.com>
date Mon, 04 Sep 2017 08:59:52 -0700
parents b6a146f0a61b
children f34110e28a0a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 test logistic regression
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
22
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
7 import numpy as np
11
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 import os
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import unittest
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 from tvii import logistic_regression
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12 class LogisticRegresionTests(unittest.TestCase):
22
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
13
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
14 def test_cost(self):
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
15 """test cost function"""
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
16
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
17 w, b, X, Y = (np.array([[1],[2]]),
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
18 2,
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
19 np.array([[1,2],[3,4]]),
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
20 np.array([[1,0]]))
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
21
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
22 expected_cost = 6.000064773192205
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
23 cost = logistic_regression.cost_function(w, b, X, Y)
3713c6733990 [logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents: 11
diff changeset
24 print cost
11
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
25
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
26 if __name__ == '__main__':
b6a146f0a61b [logistic regression] stubbing
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
27 unittest.main()