File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ Expected error reduction framework for active learning.
3+ """
4+
5+ from typing import Tuple
6+
7+ import numpy as np
8+
9+ from scipy .stats import entropy
10+ from sklearn .base import clone
11+
12+ from modAL .models import ActiveLearner
13+ from modAL .utils .data import modALinput , data_vstack
14+ from modAL .utils .selection import multi_argmax
15+
16+
17+ def expected_error_reduction (classifier : ActiveLearner , X : modALinput ,
18+ p_subsample = 1.0 : np .float , n_instances = 1 : int ) -> Tuple [np .ndarray , modALinput ]:
19+
20+ expected_error = np .full (shape = (len (X ), ), fill_value = - np .nan )
21+ possible_labels = np .unique (classifier .y_training )
22+
23+ for x_idx , x in enumerate (X ):
24+ # subsample the data if needed
25+ if np .random .rand () <= p_subsample :
26+ # estimate the expected error
27+ for y in possible_labels :
28+ X_new = data_vstack ((classifier .X_training , x ))
29+ y_new = None
30+
31+ refitted_estimator = clone (classifier .estimator ).fit ()
32+
33+
34+ query_idx = multi_argmax (expected_error , n_instances )
35+
36+ return query_idx , X [query_idx ]
37+
You can’t perform that action at this time.
0 commit comments