MCPcopy
hub / github.com/mne-tools/mne-python / _transform

Method _transform

mne/decoding/search_light.py:163–198  ·  view source on GitHub ↗

Aux. function to make parallel predictions/transformation.

(self, X, method)

Source from the content-addressed store, hash-verified

161 return self.fit(X, y, **fit_params).transform(X)
162
163 def _transform(self, X, method):
164 """Aux. function to make parallel predictions/transformation."""
165 X, is_nd = self._check_Xy(X)
166 orig_method = method
167 check_is_fitted(self)
168 method = _check_method(self.base_estimator, method)
169 if X.shape[-1] != len(self.estimators_):
170 raise ValueError("The number of estimators does not match X.shape[-1]")
171 # For predictions/transforms the parallelization is across the data and
172 # not across the estimators to avoid memory load.
173 parallel, p_func, n_jobs = parallel_func(
174 _sl_transform,
175 self.n_jobs,
176 max_jobs=X.shape[-1],
177 verbose=_verbose_safe_false(),
178 )
179
180 X_splits = np.array_split(X, n_jobs, axis=-1)
181 idx, est_splits = zip(*array_split_idx(self.estimators_, n_jobs))
182
183 context = _create_progressbar_context(self, X, "Transforming")
184 with context as pb:
185 y_pred = parallel(
186 p_func(est, x, method, pb.subset(pb_idx))
187 for pb_idx, est, x in zip(idx, est_splits, X_splits)
188 )
189
190 y_pred = np.concatenate(y_pred, axis=1)
191 if orig_method == "transform":
192 y_pred = y_pred.astype(X.dtype)
193 elif (
194 orig_method in ("predict", "predict_proba", "decision_function")
195 and not is_nd
196 ):
197 y_pred = y_pred.squeeze()
198 return y_pred
199
200 def transform(self, X):
201 """Transform each data slice/task with a series of independent estimators.

Callers 4

transformMethod · 0.95
predictMethod · 0.95
predict_probaMethod · 0.95
decision_functionMethod · 0.95

Calls 7

_check_XyMethod · 0.95
parallel_funcFunction · 0.85
_verbose_safe_falseFunction · 0.85
array_split_idxFunction · 0.85
subsetMethod · 0.80
_check_methodFunction · 0.70

Tested by

no test coverage detected