Replacing the NCD
distances = [(compute_ncd(x1, x), label) for x, _, label in compressed_lengths]
with the Euclidean distance
distances = [(np.sqrt(np.sum(np.square(x1-x))), label) for x, _, label in compressed_lengths]
gives you +15% test accuracy and saves you a lot of compute.