MCPcopy Index your code
hub / github.com/scikit-learn/scikit-learn / inverse_transform

Method inverse_transform

sklearn/preprocessing/_label.py:146–174  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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__()

Calls 6

check_is_fittedFunction · 0.90
get_namespaceFunction · 0.90
column_or_1dFunction · 0.90
_num_samplesFunction · 0.90
deviceFunction · 0.90
takeMethod · 0.80