Similarity Learning for Nearest Neighbor Classification