if self.mask[clf_index]:
result = []
predicted_label = clf.predict(query)
counter = 0
dists_temp = np.zeros(self.k)
for index_neighbor in idx_neighbors:
// Get only neighbors from the same class as predicted by the
// classifier (clf) to form the region of competence
target = self.DSEL_target[index_neighbor]
if target == predicted_label[0]:
// weight by distance
post_prob = self._get_scores_dsel(clf_index, index_neighbor)[target]
result.append(post_prob * dists[index_neighbor])
dists_temp[counter] = dists[index_neighbor]counter += 1if counter >= self.k:
break
competences[clf_index] = sum(result)/sum(dists_temp)
return competences
After Change
if self.mask[clf_index]:
result = []
dists_temp = []
predicted_label = clf.predict(query)[0]
for counter, neighbor in enumerate(idx_neighbors):
// Get only neighbors from the same class as predicted by the
// classifier (clf) to form the region of competence
target = self.DSEL_target[neighbor]
if target == predicted_label:
// get the posterior probability for the target class
post_prob = self._get_scores_dsel(clf_index, neighbor)[target]
// weight by distance
result.append(post_prob * dists_normalized[counter])
// keep the distance for normalization
dists_temp.append(dists_normalized[counter])
if len(result) > 0 and len(dists_temp) > 0:
competences[clf_index] = sum(result)/sum(dists_temp)
else:
competences[clf_index] = 0