Mercurial > hg > tvii
comparison tests/test_logistic_regression.py @ 29:cf7584f0a29f
test linear regression
| author | Jeff Hammel <k0scist@gmail.com> | 
|---|---|
| date | Mon, 04 Sep 2017 12:01:57 -0700 | 
| parents | 77f68c241b37 | 
| children | fa7a51df0d90 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 28:77f68c241b37 | 29:cf7584f0a29f | 
|---|---|
| 35 | 35 | 
| 36 # calculate gradient and cost | 36 # calculate gradient and cost | 
| 37 grads, cost = logistic_regression.propagate(w, b, X, Y) | 37 grads, cost = logistic_regression.propagate(w, b, X, Y) | 
| 38 | 38 | 
| 39 # compare to expected, | 39 # compare to expected, | 
| 40 dw_expected = [[ 0.99993216], [ 1.99980262]] | 40 dw_expected = np.array([[ 0.99993216], [ 1.99980262]]) | 
| 41 db_expected = 0.499935230625 | 41 db_expected = 0.499935230625 | 
| 42 cost_expected = 6.000064773192205 | 42 cost_expected = 6.000064773192205 | 
| 43 | |
| 44 self.assertAlmostEqual(cost_expected, cost) | |
| 45 self.assertAlmostEqual(grads['db'], db_expected) | |
| 46 assert grads['dw'].shape == dw_expected.shape | |
| 47 for a, b in zip(grads['dw'].flatten(), | |
| 48 dw_expected.flatten()): | |
| 49 self.assertAlmostEqual(a, b) | |
| 43 | 50 | 
| 44 | 51 | 
| 45 if __name__ == '__main__': | 52 if __name__ == '__main__': | 
| 46 unittest.main() | 53 unittest.main() | 
