def score_triple(self, results): """ @return: (Precision, Recall, F1_score) of results set wrt this tag's documents. """ real = len(self.docs) test = len(results) if test == 0: return (1.0, 1.0, 1.0) if real == 0 else (0.0, 0.0, 0.0) elif real == 0: return (0.0, 0.0, 0.0) ix = float(len(set(self.docs) & set(results))) return (ix/test, ix/real, f1_score(real, test, ix))
def f1_score(self, results): """ @return: F1 score between the tag's documents and the results set. """ return f1_score(set(self.docs), set(results))
def by_f1_score(self, map): """ @return: a sorted list of {rtag:f1score}, for related tags. """ return list(sort_v(((k, f1_score(len(self.docs), tot, ix)) for k, (ix, tot) in map.iteritems()), reverse=True))