Convert a one-hot encoding back into the corresponding labels Parameters ---------- Y : :py:class:`ndarray ` of shape `(N, C)` One-hot encoded labels. Each row corresponds to an example, with a single 1 in the column associated
(self, Y)
| 117 | return Y |
| 118 | |
| 119 | def inverse_transform(self, Y): |
| 120 | """ |
| 121 | Convert a one-hot encoding back into the corresponding labels |
| 122 | |
| 123 | Parameters |
| 124 | ---------- |
| 125 | Y : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)` |
| 126 | One-hot encoded labels. Each row corresponds to an example, with a |
| 127 | single 1 in the column associated with the label for that example |
| 128 | |
| 129 | Returns |
| 130 | ------- |
| 131 | labels : list of length `N` |
| 132 | The list of category labels corresponding to the nonzero columns in |
| 133 | `Y` |
| 134 | """ |
| 135 | C = len(self.cat2idx) |
| 136 | assert Y.ndim == 2, "Y must be 2D, but has shape {}".format(Y.shape) |
| 137 | assert Y.shape[1] == C, "Y must have {} columns, got {}".format(C, Y.shape[1]) |
| 138 | return [self.idx2cat[ix] for ix in Y.nonzero()[1]] |
| 139 | |
| 140 | |
| 141 | class Standardizer: |
nothing calls this directly
no outgoing calls
no test coverage detected