Transform labels back to original encoding. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y_original : ndarray of shape (n_samples,) Original encoding.
(self, y)
| 144 | return _encode(y, uniques=self.classes_) |
| 145 | |
| 146 | def inverse_transform(self, y): |
| 147 | """Transform labels back to original encoding. |
| 148 | |
| 149 | Parameters |
| 150 | ---------- |
| 151 | y : array-like of shape (n_samples,) |
| 152 | Target values. |
| 153 | |
| 154 | Returns |
| 155 | ------- |
| 156 | y_original : ndarray of shape (n_samples,) |
| 157 | Original encoding. |
| 158 | """ |
| 159 | check_is_fitted(self) |
| 160 | xp, _ = get_namespace(y) |
| 161 | y = column_or_1d(y, warn=True) |
| 162 | # inverse transform of empty array is empty array |
| 163 | if _num_samples(y) == 0: |
| 164 | return xp.asarray([]) |
| 165 | |
| 166 | diff = xpx.setdiff1d( |
| 167 | y, |
| 168 | xp.arange(self.classes_.shape[0], device=device(y)), |
| 169 | xp=xp, |
| 170 | ) |
| 171 | if diff.shape[0]: |
| 172 | raise ValueError("y contains previously unseen labels: %s" % str(diff)) |
| 173 | y = xp.asarray(y) |
| 174 | return xp.take(self.classes_, y, axis=0) |
| 175 | |
| 176 | def __sklearn_tags__(self): |
| 177 | tags = super().__sklearn_tags__() |