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

Function purity2

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

Source from the content-addressed store, hash-verified

33
34# hard labels
35def purity2(Y, R):
36 # maximum purity is 1, higher is better
37 C = np.argmax(R, axis=1) # cluster assignments
38
39 N = len(Y) # number of data pts
40 K = len(set(Y)) # number of labels
41
42 total = 0.0
43 for k in range(K):
44 max_intersection = 0
45 for j in range(K):
46 intersection = ((C == k) & (Y == j)).sum()
47 if intersection > max_intersection:
48 max_intersection = intersection
49 total += max_intersection
50 return total / N
51
52
53def purity(Y, R):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected