-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable_uncertainty.py
More file actions
70 lines (44 loc) · 1.76 KB
/
Copy pathvariable_uncertainty.py
File metadata and controls
70 lines (44 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Active Learning 18
@author: Albert França Josuá Costa
@email: albertfrancajosuacosta@gmail.com
"""
from .base import ActiveLearningBase
class VariableUncertainty (ActiveLearningBase):
r"""Strategy of Active Learning to select instances more significative based on uncertainty.
The variable uncertainty sampler selects samples for labeling based on the uncertainty of the prediction.
The higher the uncertainty, the more likely the sample will be selected for labeling. The uncertainty
measure is compared with a random variable uncertainty limit.
References
----------
[^1]: I. Zliobaite, A. Bifet, B.Pfahringer, G. Holmes. “Active Learning with Drifting Streaming Data”, IEEE Transactions on Neural Netowrks and Learning Systems, Vol.25 (1), pp.27-39, 2014.
"""
def __init__(self, theta: float = 0.95, s=0.5):
super().__init__()
self.theta = theta
self.s = s
def isSignificative(self, x, y_pred) -> bool:
"""Ask for the label of a current instance.
Based on the uncertainty of the base classifier, it checks whether the current instance should be labeled.
Parameters
----------
x
Instance
y_pred
Arrays of predicted labels
Returns
-------
selected
A boolean indicating whether a label is needed.
True for selected instance.
False for not selecte instance.
"""
maximum_posteriori = max(y_pred.values())
selected = False
if maximum_posteriori < self.theta:
self.theta = self.theta*(1-self.s)
selected = True
else:
self.theta = self.theta*(1+self.s)
selected = False
return selected