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

Function max_loss

modAL/multilabel.py:75–108  ·  view source on GitHub ↗

Max Loss query strategy for SVM multilabel classification. For more details on this query strategy, see Li et al., Multilabel SVM active learning for image classification (http://dx.doi.org/10.1109/ICIP.2004.1421535) Args: classifier: The multilabel classifier for whic

(classifier: OneVsRestClassifier, X_pool: modALinput,
             n_instances: int = 1, random_tie_break: bool = False)

Source from the content-addressed store, hash-verified

73
74
75def max_loss(classifier: OneVsRestClassifier, X_pool: modALinput,
76 n_instances: int = 1, random_tie_break: bool = False) -> np.ndarray:
77
78 """
79 Max Loss query strategy for SVM multilabel classification.
80
81 For more details on this query strategy, see
82 Li et al., Multilabel SVM active learning for image classification
83 (http://dx.doi.org/10.1109/ICIP.2004.1421535)
84
85 Args:
86 classifier: The multilabel classifier for which the labels are to be queried. Should be an SVM model
87 such as the ones from sklearn.svm. Although the function will execute for other models as well,
88 the mathematical calculations in Li et al. work only for SVM-s.
89 X_pool: The pool of samples to query from.
90 random_tie_break: If True, shuffles utility scores to randomize the order. This
91 can be used to break the tie when the highest utility score is not unique.
92
93 Returns:
94 The index of the instance from X_pool chosen to be labelled;
95 The instance from X_pool chosen to be labelled.
96 The SVM-loss-max metric of the chosen instances;
97
98 """
99
100 assert len(X_pool) >= n_instances, 'n_instances cannot be larger than len(X_pool)'
101
102 most_certain_classes = classifier.predict_proba(X_pool).argmax(axis=1)
103 loss = _SVM_loss(classifier, X_pool, most_certain_classes=most_certain_classes)
104
105 if not random_tie_break:
106 return multi_argmax(loss, n_instances)
107
108 return shuffled_argmax(loss, n_instances)
109
110
111def mean_max_loss(classifier: OneVsRestClassifier, X_pool: modALinput,

Callers

nothing calls this directly

Calls 4

multi_argmaxFunction · 0.90
shuffled_argmaxFunction · 0.90
_SVM_lossFunction · 0.85
predict_probaMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…