def nne(dim_red, true_labels):
<EOL>bt = BallTree(dim_red.T)<EOL>correct = <NUM_LIT:0><EOL>for i, l in enumerate(true_labels):<EOL><INDENT>dist, ind = bt.query([dim_red[:,i]], k=<NUM_LIT:2>)<EOL>closest_cell = ind[<NUM_LIT:0>, <NUM_LIT:1>]<EOL>if true_labels[closest_cell] == l:<EOL><INDENT>correct += <NUM_LIT:1><EOL><DEDENT><DEDENT>return float(correct)/len(true_labels)<EOL>
Calculates the nearest neighbor accuracy (basically leave-one-out cross
validation with a 1NN classifier).

Args:
    dim_red (array): dimensions (k, cells)
    true_labels (array): 1d array of integers

Returns:
    Nearest neighbor accuracy - fraction of points for which the 1NN
    1NN classifier returns the correct value.