Mercurial > hg > tvii
annotate tests/test_logistic_regression.py @ 27:22218d90d33f
[requirements] add requirements file + fix tox
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 04 Sep 2017 11:38:46 -0700 |
parents | f34110e28a0a |
children | 77f68c241b37 |
rev | line source |
---|---|
11 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 test logistic regression | |
5 """ | |
6 | |
22
3713c6733990
[logistic regression] introduce illustrative test
Jeff Hammel <k0scist@gmail.com>
parents:
11
diff
changeset
|
7 import numpy as np |
11 | 8 import os |
9 import unittest | |
10 from tvii import logistic_regression | |
11 | |
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) |
23
f34110e28a0a
[logistic regression] we have a working cost function
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
24 assert abs(cost - expected_cost) < 1e-6 |
11 | 25 |
26 if __name__ == '__main__': | |
27 unittest.main() |