def exact_expected_fscore_naive(probs, thresh):
"""NB: This algorithm is exponential in the size of probs!
Based on initial measurements, less than 15 items is
sub-second. 16 = 2s, 17=4s, 18=8s, and, well, you know
the rest...
possible relaxation to allow larger number of products:
force items with sufficiently low probs (e.g. < 1%) off
in groundtruths.
"""
probs = np.asarray(probs)
n = len(probs)
expected = 0
p_none = np.product(1-probs)
predict_none = p_none > thresh
predictions = (probs >= thresh).astype(np.int8)
for gt in itertools.product([0,1], repeat=n):
gt = np.array(gt)
fs = fscore(predictions, gt, predict_none)
p = gt_prob(gt, probs)
expected += fs * p
return expected
评论列表
文章目录