Did you mean 

    weight = recip_freq[le.transform(classes)] / np.mean(recip_freq)

in the last line? because we need only the weights corresponding to the classes given,