[MRG] FIX for exception thrown when y does not have all classes

This is a fix for #3581
`recip_freq != 0` should be computed only once.

```python
nonzero_mask = recip_freq != 0
recip_freq[nonzero_mask] = 1 / recip_freq[nonzero_mask]
```