MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / purity

Function purity

unsupervised_class/kmeans_mnist.py:53–66  ·  view source on GitHub ↗
(Y, R)

Source from the content-addressed store, hash-verified

51
52
53def purity(Y, R):
54 # maximum purity is 1, higher is better
55 N, K = R.shape
56 p = 0
57 for k in range(K):
58 best_target = -1 # we don't strictly need to store this
59 max_intersection = 0
60 for j in range(K):
61 intersection = R[Y==j, k].sum()
62 if intersection > max_intersection:
63 max_intersection = intersection
64 best_target = j
65 p += max_intersection
66 return p / N
67
68
69# hard labels

Callers 4

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected