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

Function purity

unsupervised_class/tweets.py:123–135  ·  view source on GitHub ↗
(true_labels, cluster_assignments, categories)

Source from the content-addressed store, hash-verified

121
122### calculate the purity of our clusters ###
123def purity(true_labels, cluster_assignments, categories):
124 # maximum purity is 1, higher is better
125 N = len(true_labels)
126
127 total = 0.0
128 for k in categories:
129 max_intersection = 0
130 for j in categories:
131 intersection = ((cluster_assignments == k) & (true_labels == j)).sum()
132 if intersection > max_intersection:
133 max_intersection = intersection
134 total += max_intersection
135 return total / N
136
137print("purity:", purity(Y, C, categories))
138

Callers 1

tweets.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected