1AI::DecisionTree(3) User Contributed Perl Documentation AI::DecisionTree(3)
2
3
4
6 AI::DecisionTree - Automatically Learns Decision Trees
7
9 version 0.11
10
12 use AI::DecisionTree;
13 my $dtree = new AI::DecisionTree;
14
15 # A set of training data for deciding whether to play tennis
16 $dtree->add_instance
17 (attributes => {outlook => 'sunny',
18 temperature => 'hot',
19 humidity => 'high'},
20 result => 'no');
21
22 $dtree->add_instance
23 (attributes => {outlook => 'overcast',
24 temperature => 'hot',
25 humidity => 'normal'},
26 result => 'yes');
27
28 ... repeat for several more instances, then:
29 $dtree->train;
30
31 # Find results for unseen instances
32 my $result = $dtree->get_result
33 (attributes => {outlook => 'sunny',
34 temperature => 'hot',
35 humidity => 'normal'});
36
38 The "AI::DecisionTree" module automatically creates so-called "decision
39 trees" to explain a set of training data. A decision tree is a kind of
40 categorizer that use a flowchart-like process for categorizing new
41 instances. For instance, a learned decision tree might look like the
42 following, which classifies for the concept "play tennis":
43
44 OUTLOOK
45 / | \
46 / | \
47 / | \
48 sunny/ overcast \rainy
49 / | \
50 HUMIDITY | WIND
51 / \ *no* / \
52 / \ / \
53 high/ \normal / \
54 / \ strong/ \weak
55 *no* *yes* / \
56 *no* *yes*
57
58 (This example, and the inspiration for the "AI::DecisionTree" module,
59 come directly from Tom Mitchell's excellent book "Machine Learning",
60 available from McGraw Hill.)
61
62 A decision tree like this one can be learned from training data, and
63 then applied to previously unseen data to obtain results that are
64 consistent with the training data.
65
66 The usual goal of a decision tree is to somehow encapsulate the
67 training data in the smallest possible tree. This is motivated by an
68 "Occam's Razor" philosophy, in which the simplest possible explanation
69 for a set of phenomena should be preferred over other explanations.
70 Also, small trees will make decisions faster than large trees, and they
71 are much easier for a human to look at and understand. One of the
72 biggest reasons for using a decision tree instead of many other machine
73 learning techniques is that a decision tree is a much more scrutable
74 decision maker than, say, a neural network.
75
76 The current implementation of this module uses an extremely simple
77 method for creating the decision tree based on the training instances.
78 It uses an Information Gain metric (based on expected reduction in
79 entropy) to select the "most informative" attribute at each node in the
80 tree. This is essentially the ID3 algorithm