MCPcopy
hub / github.com/MingchaoZhu/DeepLearning / calculate_entropy

Function calculate_entropy

code/chapter5.py:412–420  ·  view source on GitHub ↗
(y)

Source from the content-addressed store, hash-verified

410
411
412def calculate_entropy(y):
413 log2 = lambda x: math.log(x) / math.log(2)
414 unique_labels = np.unique(y)
415 entropy = 0
416 for label in unique_labels:
417 count = len(y[y == label])
418 p = count / len(y)
419 entropy += -p * log2(p)
420 return entropy
421
422
423def calculate_gini(y):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected