1 """Handy functions to produce scores and decisions for a list of documents.
2
3 For tuning thresholds, see L{Thresholder}.
4 """
5
7 """Score all docs using a classifier.
8
9 @param classifier : A binary classifier
10 @param docs : A list of docs of type L{AtomVector}
11 @return : A list of scores corresponding to the `docs`
12 """
13 return [classifier.score(d) for d in docs]
14
16 """Makes decisions based on given thresholds for all docs using a multiclassifier.
17
18 @param classifier : A L{MultiClassifier}
19 @param docs : List of docs
20 @param thresholds : A label:float dictionary
21 @return : A list of sets of positive labels
22 """
23 return [applyThresholds(classifier.score(d), thresholds) for d in docs]
24
25
27 """Apply thresholds to a label:score dictionary corresponding to a single doc.
28
29 @param scores : A label:float dictionary of L{MultiClassifier}-produced scores
30 @param thresholds : A label:float dictionary of thresholds
31 @return : A set of positive labels
32 """
33
34 return set([cat for cat, score in scores.iteritems() if score >= thresholds[cat]])
35