Query our top :n_instances: to request for labeling. Refer to Cardoso et al.'s "Ranked batch-mode active learning": https://www.sciencedirect.com/science/article/pii/S0020025516313949 Args: classifier: One of modAL's supported active learning models. unlabeled:
(classifier: Union[BaseLearner, BaseCommittee],
unlabeled: modALinput,
uncertainty_scores: np.ndarray,
n_instances: int,
metric: Union[str, Callable],
n_jobs: Union[int, None])
| 119 | |
| 120 | |
| 121 | def ranked_batch(classifier: Union[BaseLearner, BaseCommittee], |
| 122 | unlabeled: modALinput, |
| 123 | uncertainty_scores: np.ndarray, |
| 124 | n_instances: int, |
| 125 | metric: Union[str, Callable], |
| 126 | n_jobs: Union[int, None]) -> np.ndarray: |
| 127 | """ |
| 128 | Query our top :n_instances: to request for labeling. |
| 129 | |
| 130 | Refer to Cardoso et al.'s "Ranked batch-mode active learning": |
| 131 | https://www.sciencedirect.com/science/article/pii/S0020025516313949 |
| 132 | |
| 133 | Args: |
| 134 | classifier: One of modAL's supported active learning models. |
| 135 | unlabeled: Set of records to be considered for our active learning model. |
| 136 | uncertainty_scores: Our classifier's predictions over the response variable. |
| 137 | n_instances: Limit on the number of records to query from our unlabeled set. |
| 138 | metric: This parameter is passed to :func:`~sklearn.metrics.pairwise.pairwise_distances`. |
| 139 | n_jobs: This parameter is passed to :func:`~sklearn.metrics.pairwise.pairwise_distances`. |
| 140 | |
| 141 | Returns: |
| 142 | The indices of the top n_instances ranked unlabelled samples. |
| 143 | The uncertainty scores of the chosen instances. |
| 144 | |
| 145 | """ |
| 146 | # Make a local copy of our classifier's training data. |
| 147 | # Define our record container and record the best cold start instance in the case of cold start. |
| 148 | |
| 149 | # transform unlabeled data if needed |
| 150 | if classifier.on_transformed: |
| 151 | unlabeled = classifier.transform_without_estimating(unlabeled) |
| 152 | |
| 153 | if classifier.X_training is None: |
| 154 | best_coldstart_instance_index, labeled = select_cold_start_instance(X=unlabeled, metric=metric, n_jobs=n_jobs) |
| 155 | instance_index_ranking = [best_coldstart_instance_index] |
| 156 | elif data_shape(classifier.X_training)[0] > 0: |
| 157 | labeled = classifier.transform_without_estimating( |
| 158 | classifier.X_training |
| 159 | ) if classifier.on_transformed else classifier.X_training[:] |
| 160 | instance_index_ranking = [] |
| 161 | |
| 162 | # The maximum number of records to sample. |
| 163 | ceiling = np.minimum(unlabeled.shape[0], n_instances) - len(instance_index_ranking) |
| 164 | |
| 165 | # mask for unlabeled initialized as transparent |
| 166 | mask = np.ones(unlabeled.shape[0], bool) |
| 167 | |
| 168 | for _ in range(ceiling): |
| 169 | |
| 170 | # Receive the instance and corresponding index from our unlabeled copy that scores highest. |
| 171 | instance_index, instance, mask = select_instance(X_training=labeled, X_pool=unlabeled, |
| 172 | X_uncertainty=uncertainty_scores, mask=mask, |
| 173 | metric=metric, n_jobs=n_jobs) |
| 174 | |
| 175 | # Add our instance we've considered for labeling to our labeled set. Although we don't |
| 176 | # know it's label, we want further iterations to consider the newly-added instance so |
| 177 | # that we don't query the same instance redundantly. |
| 178 | labeled = data_vstack((labeled, instance)) |
no test coverage detected
searching dependent graphs…