snorkel.utils.probs_to_preds¶
-
snorkel.utils.
probs_to_preds
(probs, tie_break_policy='random', tol=1e-05)[source]¶ Convert an array of probabilistic labels into an array of predictions.
Policies to break ties include: “abstain”: return an abstain vote (-1) “true-random”: randomly choose among the tied options “random”: randomly choose among tied option using deterministic hash
NOTE: if tie_break_policy=”true-random”, repeated runs may have slightly different results due to difference in broken ties
- Parameters
prob – A [num_datapoints, num_classes] array of probabilistic labels such that each row sums to 1.
tie_break_policy (
str
) – Policy to break ties when converting probabilistic labels to predictionstol (
float
) – The minimum difference among probabilities to be considered a tie
- Returns
A [n] array of predictions (integers in [0, …, num_classes - 1])
- Return type
np.ndarray
Examples
>>> probs_to_preds(np.array([[0.5, 0.5, 0.5]]), tie_break_policy="abstain") array([-1]) >>> probs_to_preds(np.array([[0.8, 0.1, 0.1]])) array([0])