def purity(labels, true_labels):
purity = <NUM_LIT:0.0><EOL>for i in set(labels):<EOL><INDENT>indices = (labels==i)<EOL>true_clusters = true_labels[indices]<EOL>if len(true_clusters)==<NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>counts = Counter(true_clusters)<EOL>lab, count = counts.most_common()[<NUM_LIT:0>]<EOL>purity += count<EOL><DEDENT>return float(purity)/len(labels)<EOL>
Calculates the purity score for the given labels.

Args:
    labels (array): 1D array of integers
    true_labels (array): 1D array of integers - true labels

Returns:
    purity score - a float bewteen 0 and 1. Closer to 1 is better.