Why don't we just do it this way:

```python
y_ind = le.fit_transform(y)
# check y_ind and le.classes_ here
recip_freq = 1. / bincount(y_ind)
weight = (recip_freq / np.mean(recip_freq))
```

This relies on the fact that `le.transform(le.classes_)` is just `arange(len(le.classes_))`.

`recip_freq` obviously means "reciprocal frequency".