| 1 | diff --git a/sklearn/preprocessing/label.py b/sklearn/preprocessing/label.py |
| 2 | --- a/sklearn/preprocessing/label.py |
| 3 | +++ b/sklearn/preprocessing/label.py |
| 4 | @@ -126,6 +126,9 @@ def transform(self, y): |
| 5 | """ |
| 6 | check_is_fitted(self, 'classes_') |
| 7 | y = column_or_1d(y, warn=True) |
| 8 | + # transform of empty array is empty array |
| 9 | + if _num_samples(y) == 0: |
| 10 | + return np.array([]) |
| 11 | |
| 12 | classes = np.unique(y) |
| 13 | if len(np.intersect1d(classes, self.classes_)) < len(classes): |
| 14 | @@ -147,6 +150,10 @@ def inverse_transform(self, y): |
| 15 | y : numpy array of shape [n_samples] |
| 16 | """ |
| 17 | check_is_fitted(self, 'classes_') |
| 18 | + y = column_or_1d(y, warn=True) |
| 19 | + # inverse transform of empty array is empty array |
| 20 | + if _num_samples(y) == 0: |
| 21 | + return np.array([]) |
| 22 | |
| 23 | diff = np.setdiff1d(y, np.arange(len(self.classes_))) |
| 24 | if len(diff): |