MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / entropy

Function entropy

supervised_class/dt.py:16–24  ·  view source on GitHub ↗
(y)

Source from the content-addressed store, hash-verified

14
15
16def 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
27class TreeNode:

Callers 2

information_gainMethod · 0.70
__init__Method · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected