Skip to content

Instantly share code, notes, and snippets.

View jstypka's full-sized avatar

Jan Stypka jstypka

  • Spotify
  • Stockholm
View GitHub Profile
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):
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