(y)
| 14 | |
| 15 | |
| 16 | def entropy(y): |
| 17 | # assume y is binary - 0 or 1 |
| 18 | N = len(y) |
| 19 | s1 = (y == 1).sum() |
| 20 | if 0 == s1 or N == s1: |
| 21 | return 0 |
| 22 | p1 = float(s1) / N |
| 23 | p0 = 1 - p1 |
| 24 | return -p0*np.log2(p0) - p1*np.log2(p1) |
| 25 | |
| 26 | |
| 27 | class TreeNode: |
no outgoing calls
no test coverage detected