Transform labels to normalized encoding. Parameters ---------- y : array-like of shape (n_samples,) Target values. Returns ------- y : array-like of shape (n_samples,) Labels as normalized encodings.
(self, y)
| 122 | return y |
| 123 | |
| 124 | def transform(self, y): |
| 125 | """Transform labels to normalized encoding. |
| 126 | |
| 127 | Parameters |
| 128 | ---------- |
| 129 | y : array-like of shape (n_samples,) |
| 130 | Target values. |
| 131 | |
| 132 | Returns |
| 133 | ------- |
| 134 | y : array-like of shape (n_samples,) |
| 135 | Labels as normalized encodings. |
| 136 | """ |
| 137 | check_is_fitted(self) |
| 138 | xp, _ = get_namespace(y) |
| 139 | y = column_or_1d(y, dtype=self.classes_.dtype, warn=True) |
| 140 | # transform of empty array is empty array |
| 141 | if _num_samples(y) == 0: |
| 142 | return xp.asarray([]) |
| 143 | |
| 144 | return _encode(y, uniques=self.classes_) |
| 145 | |
| 146 | def inverse_transform(self, y): |
| 147 | """Transform labels back to original encoding. |