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

Function check_class_proba

modAL/utils/validation.py:30–55  ·  view source on GitHub ↗

Checks the class probabilities and reshapes it if not all labels are present in the classifier. Args: proba: The class probabilities of a classifier. known_labels: The class labels known by the classifier. all_labels: All class labels. Returns: Class pr

(proba: np.ndarray, known_labels: Sequence, all_labels: Sequence)

Source from the content-addressed store, hash-verified

28
29
30def check_class_proba(proba: np.ndarray, known_labels: Sequence, all_labels: Sequence) -> np.ndarray:
31 """
32 Checks the class probabilities and reshapes it if not all labels are present in the classifier.
33
34 Args:
35 proba: The class probabilities of a classifier.
36 known_labels: The class labels known by the classifier.
37 all_labels: All class labels.
38
39 Returns:
40 Class probabilities augmented such that the probability of all classes is present. If the classifier is unaware
41 of a particular class, all probabilities are zero.
42 """
43 # TODO: rewrite this function using numpy.insert
44
45 label_idx_map = -np.ones(len(all_labels), dtype='int')
46
47 for known_label_idx, known_label in enumerate(known_labels):
48 # finds the position of label in all_labels
49 for label_idx, label in enumerate(all_labels):
50 if np.array_equal(label, known_label):
51 label_idx_map[label_idx] = known_label_idx
52 break
53
54 aug_proba = np.hstack((proba, np.zeros(shape=(proba.shape[0], 1))))
55 return aug_proba[:, label_idx_map]

Callers 1

vote_probaMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…