MCPcopy Create free account
hub / github.com/modAL-python/modAL / transform_without_estimating

Method transform_without_estimating

modAL/models/base.py:60–100  ·  view source on GitHub ↗

Transforms the data as supplied to the estimator. * In case the estimator is an skearn pipeline, it applies all pipeline components but the last one. * In case the estimator is an ensemble, it concatenates the transformations for each classfier (pipeline) in the

(self, X: modALinput)

Source from the content-addressed store, hash-verified

58 self.force_all_finite = force_all_finite
59
60 def transform_without_estimating(self, X: modALinput) -> Union[np.ndarray, sp.csr_matrix]:
61 """
62 Transforms the data as supplied to the estimator.
63
64 * In case the estimator is an skearn pipeline, it applies all pipeline components but the last one.
65 * In case the estimator is an ensemble, it concatenates the transformations for each classfier
66 (pipeline) in the ensemble.
67 * Otherwise returns the non-transformed dataset X
68 Args:
69 X: dataset to be transformed
70
71 Returns:
72 Transformed data set
73 """
74 Xt = []
75 pipes = [self.estimator]
76
77 if isinstance(self.estimator, _BaseHeterogeneousEnsemble):
78 pipes = self.estimator.estimators_
79
80 ################################
81 # transform data with pipelines used by estimator
82 for pipe in pipes:
83 if isinstance(pipe, Pipeline):
84 # NOTE: The used pipeline class might be an extension to sklearn's!
85 # Create a new instance of the used pipeline class with all
86 # components but the final estimator, which is replaced by an empty (passthrough) component.
87 # This prevents any special handling of the final transformation pipe, which is usually
88 # expected to be an estimator.
89 transformation_pipe = pipe.__class__(
90 steps=[*pipe.steps[:-1], ('passthrough', 'passthrough')])
91 Xt.append(transformation_pipe.transform(X))
92
93 # in case no transformation pipelines are used by the estimator,
94 # return the original, non-transfored data
95 if not Xt:
96 return X
97
98 ################################
99 # concatenate all transformations and return
100 return data_hstack(Xt)
101
102 def _fit_on_new(self, X: modALinput, y: modALinput, bootstrap: bool = False, **fit_kwargs) -> 'BaseLearner':
103 """

Callers 2

ranked_batchFunction · 0.45

Calls 1

data_hstackFunction · 0.90

Tested by

no test coverage detected