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

Class ActiveLearner

modAL/models/learners.py:20–180  ·  view source on GitHub ↗

This class is an model of a general classic (machine learning) active learning algorithm. Args: estimator: The estimator to be used in the active learning loop. query_strategy: Function providing the query strategy for the active learning loop, for instance, mod

Source from the content-addressed store, hash-verified

18
19
20class ActiveLearner(BaseLearner):
21 """
22 This class is an model of a general classic (machine learning) active learning algorithm.
23
24 Args:
25 estimator: The estimator to be used in the active learning loop.
26 query_strategy: Function providing the query strategy for the active learning loop,
27 for instance, modAL.uncertainty.uncertainty_sampling.
28 X_training: Initial training samples, if available.
29 y_training: Initial training labels corresponding to initial training samples.
30 bootstrap_init: If initial training data is available, bootstrapping can be done during the first training.
31 Useful when building Committee models with bagging.
32 on_transformed: Whether to transform samples with the pipeline defined by the estimator
33 when applying the query strategy.
34 **fit_kwargs: keyword arguments.
35
36 Attributes:
37 estimator: The estimator to be used in the active learning loop.
38 query_strategy: Function providing the query strategy for the active learning loop.
39 X_training: If the model hasn't been fitted yet it is None, otherwise it contains the samples
40 which the model has been trained on. If provided, the method fit() of estimator is called during __init__()
41 y_training: The labels corresponding to X_training.
42
43 Examples:
44
45 >>> from sklearn.datasets import load_iris
46 >>> from sklearn.ensemble import RandomForestClassifier
47 >>> from modAL.models import ActiveLearner
48 >>> iris = load_iris()
49 >>> # give initial training examples
50 >>> X_training = iris['data'][[0, 50, 100]]
51 >>> y_training = iris['target'][[0, 50, 100]]
52 >>>
53 >>> # initialize active learner
54 >>> learner = ActiveLearner(
55 ... estimator=RandomForestClassifier(),
56 ... X_training=X_training, y_training=y_training
57 ... )
58 >>>
59 >>> # querying for labels
60 >>> query_idx, query_sample = learner.query(iris['data'])
61 >>>
62 >>> # ...obtaining new labels from the Oracle...
63 >>>
64 >>> # teaching newly labelled examples
65 >>> learner.teach(
66 ... X=iris['data'][query_idx].reshape(1, -1),
67 ... y=iris['target'][query_idx].reshape(1, )
68 ... )
69 """
70
71 def __init__(self,
72 estimator: BaseEstimator,
73 query_strategy: Callable = uncertainty_sampling,
74 X_training: Optional[modALinput] = None,
75 y_training: Optional[modALinput] = None,
76 bootstrap_init: bool = False,
77 on_transformed: bool = False,

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…