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

Function margin_sampling

modAL/uncertainty.py:160–183  ·  view source on GitHub ↗

Margin sampling query strategy. Selects the instances where the difference between the first most likely and second most likely classes are the smallest. Args: classifier: The classifier for which the labels are to be queried. X: The pool of samples to query from.

(classifier: BaseEstimator, X: modALinput,
                    n_instances: int = 1, random_tie_break: bool = False,
                    **uncertainty_measure_kwargs)

Source from the content-addressed store, hash-verified

158
159
160def margin_sampling(classifier: BaseEstimator, X: modALinput,
161 n_instances: int = 1, random_tie_break: bool = False,
162 **uncertainty_measure_kwargs) -> np.ndarray:
163 """
164 Margin sampling query strategy. Selects the instances where the difference between
165 the first most likely and second most likely classes are the smallest.
166 Args:
167 classifier: The classifier for which the labels are to be queried.
168 X: The pool of samples to query from.
169 n_instances: Number of samples to be queried.
170 random_tie_break: If True, shuffles utility scores to randomize the order. This
171 can be used to break the tie when the highest utility score is not unique.
172 **uncertainty_measure_kwargs: Keyword arguments to be passed for the uncertainty
173 measure function.
174 Returns:
175 The indices of the instances from X chosen to be labelled.
176 The margin metric of the chosen instances.
177 """
178 margin = classifier_margin(classifier, X, **uncertainty_measure_kwargs)
179
180 if not random_tie_break:
181 return multi_argmin(margin, n_instances=n_instances)
182
183 return shuffled_argmin(margin, n_instances=n_instances)
184
185
186def entropy_sampling(classifier: BaseEstimator, X: modALinput,

Callers

nothing calls this directly

Calls 3

multi_argminFunction · 0.90
shuffled_argminFunction · 0.90
classifier_marginFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…