ai4r 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +21 -20
- data/examples/decision_trees/id3_example.rb +3 -2
- data/examples/genetic_algorithm/genetic_algorithm_example.rb +6 -6
- data/examples/neural_network/backpropagation_example.rb +2 -2
- data/lib/ai4r/classifiers/classifier_helper.rb +54 -0
- data/lib/ai4r/classifiers/id3.rb +356 -0
- data/lib/ai4r/classifiers/one_r.rb +148 -0
- data/lib/ai4r/classifiers/prism.rb +231 -0
- data/lib/ai4r/classifiers/zero_r.rb +104 -0
- data/lib/ai4r/genetic_algorithm/genetic_algorithm.rb +272 -0
- data/lib/ai4r/neural_network/backpropagation.rb +271 -0
- data/site/build/tmp/locationmap.xml +14 -14
- data/site/build/tmp/output.xmap +23 -23
- data/site/build/tmp/pluginlist2fetchbuild.xml +144 -144
- data/site/build/tmp/plugins-1.xml +0 -11
- data/site/build/tmp/plugins-2.xml +54 -0
- data/site/build/tmp/projfilters.properties +41 -41
- data/site/build/webapp/WEB-INF/logs/core.log +681 -788
- data/site/build/webapp/WEB-INF/logs/error.log +281 -248
- data/site/build/webapp/WEB-INF/logs/sitemap.log +1015 -0
- data/site/src/documentation/content/xdocs/forum.html +9 -0
- data/site/src/documentation/content/xdocs/geneticAlgorithms.xml +82 -68
- data/site/src/documentation/content/xdocs/index.xml +47 -18
- data/site/src/documentation/content/xdocs/machineLearning.xml +10 -9
- data/site/src/documentation/content/xdocs/neuralNetworks.xml +60 -36
- data/site/src/documentation/content/xdocs/site.xml +8 -5
- data/site/src/documentation/content/xdocs/svn.xml +11 -1
- data/site/src/documentation/resources/images/Thumbs.db +0 -0
- data/site/src/documentation/resources/images/ai4r-logo.png +0 -0
- data/site/src/documentation/resources/images/genetic_algorithms_example.png +0 -0
- data/site/src/documentation/resources/images/jadeferret.png +0 -0
- data/site/src/documentation/resources/images/neural_network_example.png +0 -0
- data/site/src/documentation/resources/images/sub-dir/Thumbs.db +0 -0
- data/site/src/documentation/skinconf.xml +18 -18
- data/test/classifiers/id3_test.rb +206 -0
- data/test/classifiers/one_r_test.rb +62 -0
- data/test/classifiers/prism_test.rb +83 -0
- data/test/classifiers/zero_r_test.rb +48 -0
- data/test/genetic_algorithm/chromosome_test.rb +41 -38
- data/test/genetic_algorithm/genetic_algorithm_test.rb +64 -61
- data/test/neural_network/backpropagation_test.rb +20 -18
- metadata +109 -199
- data/lib/decision_tree/id3.rb +0 -354
- data/lib/genetic_algorithm/genetic_algorithm.rb +0 -268
- data/lib/neural_network/backpropagation.rb +0 -264
- data/site/build/site/en/broken-links.xml +0 -2
- data/site/build/site/en/downloads.html +0 -187
- data/site/build/site/en/downloads.pdf +0 -151
- data/site/build/site/en/geneticAlgorithms.html +0 -564
- data/site/build/site/en/geneticAlgorithms.pdf +0 -911
- data/site/build/site/en/images/ai4r-logo.png +0 -0
- data/site/build/site/en/images/built-with-forrest-button.png +0 -0
- data/site/build/site/en/images/c.png +0 -0
- data/site/build/site/en/images/c_wbn.png +0 -0
- data/site/build/site/en/images/c_wn.png +0 -0
- data/site/build/site/en/images/ero.gif +0 -0
- data/site/build/site/en/images/europe2.png +0 -0
- data/site/build/site/en/images/europe3.png +0 -0
- data/site/build/site/en/images/fitness.png +0 -0
- data/site/build/site/en/images/instruction_arrow.png +0 -0
- data/site/build/site/en/images/my_email.png +0 -0
- data/site/build/site/en/images/rubyforge.png +0 -0
- data/site/build/site/en/images/s.png +0 -0
- data/site/build/site/en/images/s_wbn.png +0 -0
- data/site/build/site/en/images/s_wn.png +0 -0
- data/site/build/site/en/images/sigmoid.png +0 -0
- data/site/build/site/en/images/t.png +0 -0
- data/site/build/site/en/images/t_wbn.png +0 -0
- data/site/build/site/en/images/t_wn.png +0 -0
- data/site/build/site/en/index.html +0 -258
- data/site/build/site/en/index.pdf +0 -306
- data/site/build/site/en/linkmap.html +0 -231
- data/site/build/site/en/linkmap.pdf +0 -94
- data/site/build/site/en/locationmap.xml +0 -72
- data/site/build/site/en/machineLearning.html +0 -325
- data/site/build/site/en/machineLearning.pdf +0 -337
- data/site/build/site/en/neuralNetworks.html +0 -446
- data/site/build/site/en/neuralNetworks.pdf +0 -604
- data/site/build/site/en/skin/CommonMessages_de.xml +0 -23
- data/site/build/site/en/skin/CommonMessages_en_US.xml +0 -23
- data/site/build/site/en/skin/CommonMessages_es.xml +0 -23
- data/site/build/site/en/skin/CommonMessages_fr.xml +0 -23
- data/site/build/site/en/skin/basic.css +0 -166
- data/site/build/site/en/skin/breadcrumbs-optimized.js +0 -90
- data/site/build/site/en/skin/breadcrumbs.js +0 -237
- data/site/build/site/en/skin/fontsize.js +0 -166
- data/site/build/site/en/skin/getBlank.js +0 -40
- data/site/build/site/en/skin/getMenu.js +0 -45
- data/site/build/site/en/skin/images/README.txt +0 -1
- data/site/build/site/en/skin/images/add.jpg +0 -0
- data/site/build/site/en/skin/images/built-with-forrest-button.png +0 -0
- data/site/build/site/en/skin/images/chapter.gif +0 -0
- data/site/build/site/en/skin/images/chapter_open.gif +0 -0
- data/site/build/site/en/skin/images/current.gif +0 -0
- data/site/build/site/en/skin/images/error.png +0 -0
- data/site/build/site/en/skin/images/external-link.gif +0 -0
- data/site/build/site/en/skin/images/fix.jpg +0 -0
- data/site/build/site/en/skin/images/forrest-credit-logo.png +0 -0
- data/site/build/site/en/skin/images/hack.jpg +0 -0
- data/site/build/site/en/skin/images/header_white_line.gif +0 -0
- data/site/build/site/en/skin/images/info.png +0 -0
- data/site/build/site/en/skin/images/instruction_arrow.png +0 -0
- data/site/build/site/en/skin/images/label.gif +0 -0
- data/site/build/site/en/skin/images/page.gif +0 -0
- data/site/build/site/en/skin/images/pdfdoc.gif +0 -0
- data/site/build/site/en/skin/images/poddoc.png +0 -0
- data/site/build/site/en/skin/images/printer.gif +0 -0
- data/site/build/site/en/skin/images/rc-b-l-15-1body-2menu-3menu.png +0 -0
- data/site/build/site/en/skin/images/rc-b-r-15-1body-2menu-3menu.png +0 -0
- data/site/build/site/en/skin/images/rc-b-r-5-1header-2tab-selected-3tab-selected.png +0 -0
- data/site/build/site/en/skin/images/rc-t-l-5-1header-2searchbox-3searchbox.png +0 -0
- data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-selected-3tab-selected.png +0 -0
- data/site/build/site/en/skin/images/rc-t-l-5-1header-2tab-unselected-3tab-unselected.png +0 -0
- data/site/build/site/en/skin/images/rc-t-r-15-1body-2menu-3menu.png +0 -0
- data/site/build/site/en/skin/images/rc-t-r-5-1header-2searchbox-3searchbox.png +0 -0
- data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-selected-3tab-selected.png +0 -0
- data/site/build/site/en/skin/images/rc-t-r-5-1header-2tab-unselected-3tab-unselected.png +0 -0
- data/site/build/site/en/skin/images/remove.jpg +0 -0
- data/site/build/site/en/skin/images/rss.png +0 -0
- data/site/build/site/en/skin/images/spacer.gif +0 -0
- data/site/build/site/en/skin/images/success.png +0 -0
- data/site/build/site/en/skin/images/txtdoc.png +0 -0
- data/site/build/site/en/skin/images/update.jpg +0 -0
- data/site/build/site/en/skin/images/valid-html401.png +0 -0
- data/site/build/site/en/skin/images/vcss.png +0 -0
- data/site/build/site/en/skin/images/warning.png +0 -0
- data/site/build/site/en/skin/images/xmldoc.gif +0 -0
- data/site/build/site/en/skin/menu.js +0 -48
- data/site/build/site/en/skin/note.txt +0 -50
- data/site/build/site/en/skin/print.css +0 -54
- data/site/build/site/en/skin/profile.css +0 -163
- data/site/build/site/en/skin/prototype.js +0 -1257
- data/site/build/site/en/skin/screen.css +0 -587
- data/site/build/site/en/svn.html +0 -223
- data/site/build/site/en/svn.pdf +0 -239
- data/site/build/site/en/wholesite.pdf +0 -1686
- data/site/build/tmp/brokenlinks.xml +0 -2
- data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.data +0 -0
- data/site/build/tmp/cocoon-work/cache-dir/cocoon-ehcache-1.index +0 -0
- data/test/decision_tree/id3_test.rb +0 -209
Binary file
|
Binary file
|
@@ -1,209 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# id3_test.rb
|
3
|
-
#
|
4
|
-
# This is a unit test file for the ID3 algorithm (Quinlan) implemented
|
5
|
-
# in ai4r
|
6
|
-
#
|
7
|
-
# Author:: Sergio Fierens
|
8
|
-
# License:: MPL 1.1
|
9
|
-
# Project:: ai4r
|
10
|
-
# Url:: http://ai4r.rubyforge.org/
|
11
|
-
#
|
12
|
-
# You can redistribute it and/or modify it under the terms of
|
13
|
-
# the Mozilla Public License version 1.1 as published by the
|
14
|
-
# Mozilla Foundation at http://www.mozilla.org/MPL/MPL-1.1.txt
|
15
|
-
#
|
16
|
-
|
17
|
-
require File.dirname(__FILE__) + '/../../lib/decision_tree/id3'
|
18
|
-
require 'test/unit'
|
19
|
-
|
20
|
-
DATA_LABELS = [ 'city', 'age_range', 'gender', 'marketing_target' ]
|
21
|
-
|
22
|
-
DATA_SET = [ ['New York', '<30', 'M', 'Y'],
|
23
|
-
['Chicago', '<30', 'M', 'Y'],
|
24
|
-
['Chicago', '<30', 'F', 'Y'],
|
25
|
-
['New York', '<30', 'M', 'Y'],
|
26
|
-
['New York', '<30', 'M', 'Y'],
|
27
|
-
['Chicago', '[30-50)', 'M', 'Y'],
|
28
|
-
['New York', '[30-50)', 'F', 'N'],
|
29
|
-
['Chicago', '[30-50)', 'F', 'Y'],
|
30
|
-
['New York', '[30-50)', 'F', 'N'],
|
31
|
-
['Chicago', '[50-80]', 'M', 'N'],
|
32
|
-
['New York', '[50-80]', 'F', 'N'],
|
33
|
-
['New York', '[50-80]', 'M', 'N'],
|
34
|
-
['Chicago', '[50-80]', 'M', 'N'],
|
35
|
-
['New York', '[50-80]', 'F', 'N'],
|
36
|
-
['Chicago', '>80', 'F', 'Y']
|
37
|
-
]
|
38
|
-
|
39
|
-
SPLIT_DATA_SET_BY_CITY = [ [
|
40
|
-
["New York", "<30", "M", "Y"],
|
41
|
-
["New York", "<30", "M", "Y"],
|
42
|
-
["New York", "<30", "M", "Y"],
|
43
|
-
["New York", "[30-50)", "F", "N"],
|
44
|
-
["New York", "[30-50)", "F", "N"],
|
45
|
-
["New York", "[50-80]", "F", "N"],
|
46
|
-
["New York", "[50-80]", "M", "N"],
|
47
|
-
["New York", "[50-80]", "F", "N"]],
|
48
|
-
[
|
49
|
-
["Chicago", "<30", "M", "Y"],
|
50
|
-
["Chicago", "<30", "F", "Y"],
|
51
|
-
["Chicago", "[30-50)", "M", "Y"],
|
52
|
-
["Chicago", "[30-50)", "F", "Y"],
|
53
|
-
["Chicago", "[50-80]", "M", "N"],
|
54
|
-
["Chicago", "[50-80]", "M", "N"],
|
55
|
-
["Chicago", ">80", "F", "Y"]]
|
56
|
-
]
|
57
|
-
|
58
|
-
SPLIT_DATA_SET_BY_AGE = [ [
|
59
|
-
["New York", "<30", "M", "Y"],
|
60
|
-
["Chicago", "<30", "M", "Y"],
|
61
|
-
["Chicago", "<30", "F", "Y"],
|
62
|
-
["New York", "<30", "M", "Y"],
|
63
|
-
["New York", "<30", "M", "Y"]],
|
64
|
-
[
|
65
|
-
["Chicago", "[30-50)", "M", "Y"],
|
66
|
-
["New York", "[30-50)", "F", "N"],
|
67
|
-
["Chicago", "[30-50)", "F", "Y"],
|
68
|
-
["New York", "[30-50)", "F", "N"]],
|
69
|
-
[
|
70
|
-
["Chicago", "[50-80]", "M", "N"],
|
71
|
-
["New York", "[50-80]", "F", "N"],
|
72
|
-
["New York", "[50-80]", "M", "N"],
|
73
|
-
["Chicago", "[50-80]", "M", "N"],
|
74
|
-
["New York", "[50-80]", "F", "N"]],
|
75
|
-
[
|
76
|
-
["Chicago", ">80", "F", "Y"]]
|
77
|
-
]
|
78
|
-
|
79
|
-
EXPECTED_RULES_STRING =
|
80
|
-
"if age_range=='<30' then marketing_target='Y'\n"+
|
81
|
-
"elsif age_range=='[30-50)' and city=='Chicago' then marketing_target='Y'\n"+
|
82
|
-
"elsif age_range=='[30-50)' and city=='New York' then marketing_target='N'\n"+
|
83
|
-
"elsif age_range=='[50-80]' then marketing_target='N'\n"+
|
84
|
-
"elsif age_range=='>80' then marketing_target='Y'\n"+
|
85
|
-
"else raise 'There was not enough information during training to do a proper induction for this data element' end"
|
86
|
-
|
87
|
-
|
88
|
-
DecisionTree::ID3.send(:public, *DecisionTree::ID3.protected_instance_methods)
|
89
|
-
DecisionTree::ID3.send(:public, *DecisionTree::ID3.private_instance_methods)
|
90
|
-
|
91
|
-
module DecisionTree
|
92
|
-
|
93
|
-
class ID3Test < Test::Unit::TestCase
|
94
|
-
|
95
|
-
def test_log2
|
96
|
-
assert_equal 1.0, DecisionTree::ID3.log2(2)
|
97
|
-
assert_equal 0.0, DecisionTree::ID3.log2(0)
|
98
|
-
assert 1.585 - DecisionTree::ID3.log2(3) < 0.001
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_sum
|
102
|
-
assert_equal 28, DecisionTree::ID3.sum([5, 0, 22, 1])
|
103
|
-
assert_equal 0, DecisionTree::ID3.sum([])
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_data_labels
|
107
|
-
id3 = DecisionTree::ID3.new(DATA_SET)
|
108
|
-
expected_default = [ 'ATTRIBUTE_1', 'ATTRIBUTE_2', 'ATTRIBUTE_3', 'CATEGORY' ]
|
109
|
-
assert_equal(expected_default, id3.data_labels)
|
110
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
111
|
-
assert_equal(DATA_LABELS, id3.data_labels)
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_domain
|
115
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
116
|
-
expected_domain = [["New York", "Chicago"], ["<30", "[30-50)", "[50-80]", ">80"], ["M", "F"], ["Y", "N"]]
|
117
|
-
assert_equal expected_domain, id3.domain(DATA_SET)
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_grid
|
121
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
122
|
-
expected_grid = [[3, 5], [5, 2]]
|
123
|
-
domain = id3.domain(DATA_SET)
|
124
|
-
assert_equal expected_grid, id3.freq_grid(0, DATA_SET, domain)
|
125
|
-
expected_grid = [[5, 0], [2, 2], [0, 5], [1, 0]]
|
126
|
-
assert_equal expected_grid, id3.freq_grid(1, DATA_SET, domain)
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_entropy
|
130
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
131
|
-
expected_entropy = 0.9118
|
132
|
-
domain = id3.domain(DATA_SET)
|
133
|
-
freq_grid = id3.freq_grid(0, DATA_SET, domain)
|
134
|
-
assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
|
135
|
-
expected_entropy = 0.2667
|
136
|
-
freq_grid = id3.freq_grid(1, DATA_SET, domain)
|
137
|
-
assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
|
138
|
-
expected_entropy = 0.9688
|
139
|
-
freq_grid = id3.freq_grid(2, DATA_SET, domain)
|
140
|
-
assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_min_entropy_index
|
144
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
145
|
-
domain = id3.domain(DATA_SET)
|
146
|
-
assert_equal 1, id3.min_entropy_index(DATA_SET, domain)
|
147
|
-
assert_equal 0, id3.min_entropy_index(DATA_SET, domain, [1])
|
148
|
-
assert_equal 2, id3.min_entropy_index(DATA_SET, domain, [1, 0])
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_split_data_examples
|
152
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
153
|
-
domain = id3.domain(DATA_SET)
|
154
|
-
res = id3.split_data_examples(DATA_SET, domain, 0)
|
155
|
-
assert_equal(SPLIT_DATA_SET_BY_CITY, res)
|
156
|
-
res = id3.split_data_examples(DATA_SET, domain, 1)
|
157
|
-
assert_equal(SPLIT_DATA_SET_BY_AGE, res)
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_most_freq
|
161
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
162
|
-
domain = id3.domain(DATA_SET)
|
163
|
-
assert_equal 'Y', id3.most_freq(DATA_SET, domain)
|
164
|
-
assert_equal 'Y', id3.most_freq(SPLIT_DATA_SET_BY_AGE[3], domain)
|
165
|
-
assert_equal 'N', id3.most_freq(SPLIT_DATA_SET_BY_AGE[2], domain)
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_to_s
|
169
|
-
assert_equal [["marketing_target='N'"]], DecisionTree::CategoryNode.new('marketing_target', 'N').get_rules
|
170
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
171
|
-
assert_equal EXPECTED_RULES_STRING, id3.to_s
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_eval
|
175
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
176
|
-
#if age_range='<30' then marketing_target='Y'
|
177
|
-
assert_equal 'Y', id3.eval(['New York', '<30', 'F'])
|
178
|
-
assert_equal 'Y', id3.eval(['Chicago', '<30', 'M'])
|
179
|
-
#if age_range='[30-50)' and city='Chicago' then marketing_target='Y'
|
180
|
-
assert_equal 'Y', id3.eval(['Chicago', '[30-50)', 'F'])
|
181
|
-
assert_equal 'Y', id3.eval(['Chicago', '[30-50)', 'M'])
|
182
|
-
#if age_range='[30-50)' and city='New York' then marketing_target='N'
|
183
|
-
assert_equal 'N', id3.eval(['New York', '[30-50)', 'F'])
|
184
|
-
assert_equal 'N', id3.eval(['New York', '[30-50)', 'M'])
|
185
|
-
#if age_range='[50-80]' then marketing_target='N'
|
186
|
-
assert_equal 'N', id3.eval(['New York', '[50-80]', 'F'])
|
187
|
-
assert_equal 'N', id3.eval(['Chicago', '[50-80]', 'M'])
|
188
|
-
#if age_range='>80' then marketing_target='Y'
|
189
|
-
assert_equal 'Y', id3.eval(['New York', '>80', 'M'])
|
190
|
-
assert_equal 'Y', id3.eval(['Chicago', '>80', 'F'])
|
191
|
-
end
|
192
|
-
|
193
|
-
def test_rules_eval
|
194
|
-
id3 = DecisionTree::ID3.new(DATA_SET, DATA_LABELS)
|
195
|
-
#if age_range='<30' then marketing_target='Y'
|
196
|
-
age_range = '<30'
|
197
|
-
marketing_target = nil
|
198
|
-
eval id3.to_s
|
199
|
-
assert_equal 'Y', marketing_target
|
200
|
-
#if age_range='[30-50)' and city='New York' then marketing_target='N'
|
201
|
-
age_range='[30-50)'
|
202
|
-
city='New York'
|
203
|
-
eval id3.to_s
|
204
|
-
assert_equal 'N', marketing_target
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
|