1AI::Categorizer::LearneUrs(e3r)Contributed Perl DocumentAaIt:i:oCnategorizer::Learner(3)
2
3
4
6 AI::Categorizer::Learner - Abstract Machine Learner Class
7
9 use AI::Categorizer::Learner::NaiveBayes; # Or other subclass
10
11 # Here $k is an AI::Categorizer::KnowledgeSet object
12
13 my $nb = new AI::Categorizer::Learner::NaiveBayes(...parameters...);
14 $nb->train(knowledge_set => $k);
15 $nb->save_state('filename');
16
17 ... time passes ...
18
19 $nb = AI::Categorizer::Learner::NaiveBayes->restore_state('filename');
20 my $c = new AI::Categorizer::Collection::Files( path => ... );
21 while (my $document = $c->next) {
22 my $hypothesis = $nb->categorize($document);
23 print "Best assigned category: ", $hypothesis->best_category, "\n";
24 print "All assigned categories: ", join(', ', $hypothesis->categories), "\n";
25 }
26
28 The "AI::Categorizer::Learner" class is an abstract class that will
29 never actually be directly used in your code. Instead, you will use a
30 subclass like "AI::Categorizer::Learner::NaiveBayes" which implements
31 an actual machine learning algorithm.
32
33 The general description of the Learner interface is documented here.
34
36 new()
37 Creates a new Learner and returns it. Accepts the following
38 parameters:
39
40 knowledge_set
41 A Knowledge Set that will be used by default during the train()
42 method.
43
44 verbose
45 If true, the Learner will display some diagnostic output while
46 training and categorizing documents.
47
48 train()
49 train(knowledge_set => $k)
50 Trains the categorizer. This prepares it for later use in
51 categorizing documents. The "knowledge_set" parameter must provide
52 an object of the class "AI::Categorizer::KnowledgeSet" (or a
53 subclass thereof), populated with lots of documents and categories.
54 See AI::Categorizer::KnowledgeSet for the details of how to create
55 such an object. If you provided a "knowledge_set" parameter to
56 new(), specifying one here will override it.
57
58 categorize($document)
59 Returns an "AI::Categorizer::Hypothesis" object representing the
60 categorizer's "best guess" about which categories the given
61 document should be assigned to. See AI::Categorizer::Hypothesis
62 for more details on how to use this object.
63
64 categorize_collection(collection => $collection)
65 Categorizes every document in a collection and returns an
66 Experiment object representing the results. Note that the
67 Experiment does not contain knowledge of the assigned categories
68 for every document, only a statistical summary of the results.
69
70 knowledge_set()
71 Gets/sets the internal "knowledge_set" member. Note that since the
72 knowledge set may be enormous, some Learners may throw away their
73 knowledge set after training or after restoring state from a file.
74
75 $learner->save_state($path)
76 Saves the Learner for later use. This method is inherited from
77 "AI::Categorizer::Storable".
78
79 $class->restore_state($path)
80 Returns a Learner saved in a file with save_state(). This method
81 is inherited from "AI::Categorizer::Storable".
82
84 Ken Williams, ken@mathforum.org
85
87 Copyright 2000-2003 Ken Williams. All rights reserved.
88
89 This library is free software; you can redistribute it and/or modify it
90 under the same terms as Perl itself.
91
93 AI::Categorizer(3)
94
95
96
97perl v5.36.0 2023-01-19 AI::Categorizer::Learner(3)