This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_ones(n): | |
# How many ones are there in a numbers binary representation a.k.a. how many keywords are relevant to a sample | |
count = 0 | |
while n != 0: | |
n &= n - 1 | |
count += 1 | |
return count | |
def compute_descendant_metric(y_true, y_pred, labels, ontology): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import compress | |
import numpy as np | |
from sklearn.metrics import auc | |
def compute_precision_recall_auc(y_true, y_pred, precision_recall_fun): | |
thresholds = np.append(np.unique(y_pred), [-1]) | |
thresholds.sort() | |
precision = np.zeros(len(y_true)) # reuse them for every binarisation |