1AI::Categorizer::HypothUesseirs(C3o)ntributed Perl DocumAeIn:t:aCtaitoengorizer::Hypothesis(3)
2
3
4
6 AI::Categorizer::Hypothesis - Embodies a set of category assignments
7
9 use AI::Categorizer::Hypothesis;
10
11 # Hypotheses are usually created by the Learner's categorize() method.
12 # (assume here that $learner and $document have been created elsewhere)
13 my $h = $learner->categorize($document);
14
15 print "Assigned categories: ", join ', ', $h->categories, "\n";
16 print "Best category: ", $h->best_category, "\n";
17 print "Assigned scores: ", join ', ', $h->scores( $h->categories ), "\n";
18 print "Chosen from: ", join ', ', $h->all_categories, "\n";
19 print +($h->in_category('geometry') ? '' : 'not '), "assigned to geometry\n";
20
22 A Hypothesis embodies a set of category assignments that a categorizer
23 makes about a single document. Because one may be interested in
24 knowing different kinds of things about the assignments (for instance,
25 what categories were assigned, which category had the highest score,
26 whether a particular category was assigned), we provide a simple class
27 to help facilitate these scenarios.
28
30 new(%parameters)
31 Returns a new Hypothesis object. Generally a user of
32 "AI::Categorize" doesn't create a Hypothesis object directly - they
33 are returned by the Learner's "categorize()" method. However, if
34 you wish to create a Hypothesis directly (maybe passing it some
35 fake data for testing purposes) you may do so using the "new()"
36 method.
37
38 The following parameters are accepted when creating a new
39 Hypothesis:
40
41 all_categories
42 A required parameter which gives the set of all categories that
43 could possibly be assigned to. The categories should be
44 specified as a reference to an array of category names (as
45 strings).
46
47 scores
48 A hash reference indicating the assignment score for each
49 category. Any score higher than the "threshold" will be
50 considered to be assigned.
51
52 threshold
53 A number controlling which categories should be assigned - any
54 category whose score is greater than or equal to "threshold"
55 will be assigned, any category whose score is lower than
56 "threshold" will not be assigned.
57
58 document_name
59 An optional string parameter indicating the name of the
60 document about which this hypothesis was made.
61
62 categories()
63 Returns an ordered list of the categories the document was placed
64 in, with best matches first. Categories are returned by their
65 string names.
66
67 best_category()
68 Returns the name of the category with the highest score in this
69 hypothesis. Bear in mind that this category may not actually be
70 assigned if no categories' scores exceed the threshold.
71
72 in_category($name)
73 Returns true or false depending on whether the document was placed
74 in the given category.
75
76 scores(@names)
77 Returns a list of result scores for the given categories. Since
78 the interface is still changing, and since different Learners
79 implement scoring in different ways, not very much can officially
80 be said about the scores, except that a good score is higher than a
81 bad score. Individual Learners will have their own procedures for
82 determining scores, so you cannot compare one Learner's score with
83 another Learner's - for instance, one Learner might always give
84 scores between 0 and 1, and another Learner might always return
85 scores less than 0. You often cannot compare scores from a single
86 Learner on two different categorization tasks either.
87
88 all_categories()
89 Returns the list of category names specified with the
90 "all_categories" constructor parameter.
91
92 document_name()
93 Returns the value of the "document_name" parameter specified as a
94 constructor parameter, or "undef" if none was specified.
95
97 Ken Williams <ken@mathforum.org>
98
100 This distribution is free software; you can redistribute it and/or
101 modify it under the same terms as Perl itself. These terms apply to
102 every file in the distribution - if you have questions, please contact
103 the author.
104
105
106
107perl v5.34.0 2021-07-22 AI::Categorizer::Hypothesis(3)