Core abstraction in modAL. Args: estimator: The estimator to be used in the active learning loop. query_strategy: Function providing the query strategy for the active learning loop, for instance, modAL.uncertainty.uncertainty_sampling. force_all_finite:
| 22 | |
| 23 | |
| 24 | class BaseLearner(ABC, BaseEstimator): |
| 25 | """ |
| 26 | Core abstraction in modAL. |
| 27 | |
| 28 | Args: |
| 29 | estimator: The estimator to be used in the active learning loop. |
| 30 | query_strategy: Function providing the query strategy for the active learning loop, |
| 31 | for instance, modAL.uncertainty.uncertainty_sampling. |
| 32 | force_all_finite: When True, forces all values of the data finite. |
| 33 | When False, accepts np.nan and np.inf values. |
| 34 | on_transformed: Whether to transform samples with the pipeline defined by the estimator |
| 35 | when applying the query strategy. |
| 36 | **fit_kwargs: keyword arguments. |
| 37 | |
| 38 | Attributes: |
| 39 | estimator: The estimator to be used in the active learning loop. |
| 40 | query_strategy: Function providing the query strategy for the active learning loop. |
| 41 | """ |
| 42 | |
| 43 | def __init__(self, |
| 44 | estimator: BaseEstimator, |
| 45 | query_strategy: Callable, |
| 46 | on_transformed: bool = False, |
| 47 | force_all_finite: bool = True, |
| 48 | **fit_kwargs |
| 49 | ) -> None: |
| 50 | assert callable(query_strategy), 'query_strategy must be callable' |
| 51 | |
| 52 | self.estimator = estimator |
| 53 | self.query_strategy = query_strategy |
| 54 | self.on_transformed = on_transformed |
| 55 | |
| 56 | assert isinstance(force_all_finite, |
| 57 | bool), 'force_all_finite must be a bool' |
| 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 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…