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

Function uncertainty_sampling

modAL/uncertainty.py:133–157  ·  view source on GitHub ↗

Uncertainty sampling query strategy. Selects the least sure instances for labelling. Args: classifier: The classifier for which the labels are to be queried. X: The pool of samples to query from. n_instances: Number of samples to be queried. random_tie_break

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

Source from the content-addressed store, hash-verified

131
132
133def uncertainty_sampling(classifier: BaseEstimator, X: modALinput,
134 n_instances: int = 1, random_tie_break: bool = False,
135 **uncertainty_measure_kwargs) -> np.ndarray:
136 """
137 Uncertainty sampling query strategy. Selects the least sure instances for labelling.
138
139 Args:
140 classifier: The classifier for which the labels are to be queried.
141 X: The pool of samples to query from.
142 n_instances: Number of samples to be queried.
143 random_tie_break: If True, shuffles utility scores to randomize the order. This
144 can be used to break the tie when the highest utility score is not unique.
145 **uncertainty_measure_kwargs: Keyword arguments to be passed for the uncertainty
146 measure function.
147
148 Returns:
149 The indices of the instances from X chosen to be labelled.
150 The uncertainty metric of the chosen instances.
151 """
152 uncertainty = classifier_uncertainty(classifier, X, **uncertainty_measure_kwargs)
153
154 if not random_tie_break:
155 return multi_argmax(uncertainty, n_instances=n_instances)
156
157 return shuffled_argmax(uncertainty, n_instances=n_instances)
158
159
160def margin_sampling(classifier: BaseEstimator, X: modALinput,

Callers

nothing calls this directly

Calls 3

multi_argmaxFunction · 0.90
shuffled_argmaxFunction · 0.90
classifier_uncertaintyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…