ai4r 1.1 → 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -39,12 +39,15 @@ See http://forrest.apache.org/docs/linking.html for more info
|
|
|
39
39
|
<site label="ai4r" href="" xmlns="http://apache.org/forrest/linkmap/1.0"
|
|
40
40
|
tab="">
|
|
41
41
|
<about label="Home">
|
|
42
|
-
<index label="Index" href="index.html" description="ai4r - Artificial Intelligence for Ruby"/>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
<index label="Index" href="index.html" description="ai4r - Artificial Intelligence for Ruby"/>
|
|
43
|
+
<practicalExamples label="Practical Examples">
|
|
44
|
+
<geneticAlgorithms label="Genetic Algorithms" href="geneticAlgorithms.html" description="Genetic Algorithms in ruby"/>
|
|
45
|
+
<machineLearning label="Machine Learning" href="machineLearning.html" description="ID3 Decision Trees in ruby"/>
|
|
46
|
+
<neuralNetworks label="Neural Networks" href="neuralNetworks.html" description="Backpropagation Neural Network in ruby" />
|
|
47
|
+
</practicalExamples>
|
|
46
48
|
<download label="Downloads" href="downloads.html" description="ai4r - Download Files"/>
|
|
47
|
-
<
|
|
49
|
+
<download label="Forum" href="forum.html" description="ai4r - Forum"/>
|
|
50
|
+
<svn label="Source Code repository" href="svn.html" description="ai4r Subversion repository"/>
|
|
48
51
|
<ai4r_site_pdf label="ai4r project PDF" href="wholesite.pdf"/>
|
|
49
52
|
</about>
|
|
50
53
|
|
|
@@ -24,7 +24,17 @@
|
|
|
24
24
|
|
|
25
25
|
<section id="moreinfor">
|
|
26
26
|
<title>More info on Subversion (svn)</title>
|
|
27
|
-
<p>If you need help about using Subversion (svn), the (IMO) best documentation is available <a href="http://svnbook.red-bean.com/">here</a
|
|
27
|
+
<p>If you need help about using Subversion (svn), the (IMO) best documentation is available <a href="http://svnbook.red-bean.com/">here</a>.</p>
|
|
28
|
+
<p>If you work in SCM, you may find <a href="http://scm.jadeferret.com">Jade Ferret’s SCM initiative</a>
|
|
29
|
+
intresting.</p>
|
|
30
|
+
</section>
|
|
31
|
+
|
|
32
|
+
<section id="softsizo_report">
|
|
33
|
+
<title>Source code evolution</title>
|
|
34
|
+
<p><a href="http://softsizo.jadeferret.com">Soft Sizo</a> is a report generation tool that extends the concept
|
|
35
|
+
of Lines Of Code (LOC) metrics, using changes information stored in a Subversion repository.</p>
|
|
36
|
+
<p>You can access <a href="http://softsizo.jadeferret.com/examples/ai4r/index.html">AI4R Soft Sizo report</a>
|
|
37
|
+
for some AI4R source code evolution metrics.
|
|
28
38
|
</p>
|
|
29
39
|
</section>
|
|
30
40
|
</body>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -59,19 +59,19 @@ which will be used to configure the chosen Forrest skin.
|
|
|
59
59
|
<!-- mandatory project logo
|
|
60
60
|
default skin: renders it at the top -->
|
|
61
61
|
<project-name>ai4r</project-name>
|
|
62
|
-
<project-description>Artificial Intelligence for Ruby</project-description>
|
|
62
|
+
<project-description>AI4R - Artificial Intelligence for Ruby</project-description>
|
|
63
63
|
<project-url>http://ai4r.rubyforge.org/</project-url>
|
|
64
64
|
<project-logo>images/ai4r-logo.png</project-logo>
|
|
65
65
|
<!-- Alternative static image:
|
|
66
66
|
<project-logo>images/project-logo.gif</project-logo> -->
|
|
67
67
|
<!-- optional group logo
|
|
68
|
-
default skin: renders it at the top-left corner
|
|
69
|
-
<group-name>
|
|
70
|
-
<group-description>
|
|
71
|
-
<group-url>http://
|
|
72
|
-
<group-logo>images/
|
|
73
|
-
<!-- Alternative static image:
|
|
74
|
-
<group-logo>images/
|
|
68
|
+
default skin: renders it at the top-left corner -->
|
|
69
|
+
<group-name>Jade Ferret</group-name>
|
|
70
|
+
<group-description>Jade Ferret</group-description>
|
|
71
|
+
<group-url>http://www.jadeferret.com</group-url>
|
|
72
|
+
<group-logo>images/jadeferret.png</group-logo>
|
|
73
|
+
<!-- Alternative static image:
|
|
74
|
+
<group-logo>images/jadeferret.gif</group-logo> -->
|
|
75
75
|
<!-- optional host logo (e.g. sourceforge logo)
|
|
76
76
|
default skin: renders it at the bottom-left corner -->
|
|
77
77
|
<host-url>http://rubyforge.org/projects/ai4r/</host-url>
|
|
@@ -82,10 +82,8 @@ which will be used to configure the chosen Forrest skin.
|
|
|
82
82
|
<disable-copyright-footer>false</disable-copyright-footer>
|
|
83
83
|
<!-- @inception enable automatic generation of a date-range to current date -->
|
|
84
84
|
<year inception="true">2007</year>
|
|
85
|
-
<vendor>Sergio Fierens</vendor>
|
|
86
|
-
|
|
87
|
-
copyright statement
|
|
88
|
-
<copyright-link>http://www.example.org/</copyright-link>-->
|
|
85
|
+
<vendor>Sergio Fierens, Jade Ferret</vendor>
|
|
86
|
+
<copyright-link>http://www.jadeferret.com/</copyright-link>
|
|
89
87
|
<!-- Some skins use this to form a 'breadcrumb trail' of links.
|
|
90
88
|
Use location="alt" to move the trail to an alternate location
|
|
91
89
|
(if the skin supports it).
|
|
@@ -208,8 +206,8 @@ which will be used to configure the chosen Forrest skin.
|
|
|
208
206
|
pelt: body: any remaining parts, e.g. the bottom of the page
|
|
209
207
|
pelt: footer: the second from bottom strip containing credit logos and published date
|
|
210
208
|
pelt: feedback: the optional bottom strip containing feedback link
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
|
|
210
|
+
|
|
213
211
|
<color name="breadtrail" value="#cedfef" font="#0F3660" link="#0F3660" vlink="#0F3660" hlink="#000066"/>
|
|
214
212
|
<color name="header" value="#294563"/>
|
|
215
213
|
<color name="tab-selected" value="#4a6d8c" link="#0F3660" vlink="#0F3660" hlink="#000066"/>
|
|
@@ -235,9 +233,9 @@ which will be used to configure the chosen Forrest skin.
|
|
|
235
233
|
<color name="warning" value="#990000"/>
|
|
236
234
|
<color name="code" value="#CFDCED"/>
|
|
237
235
|
<color name="footer" value="#cedfef"/>
|
|
238
|
-
-->
|
|
236
|
+
-->
|
|
239
237
|
<!-- Color group: Krysalis -->
|
|
240
|
-
|
|
238
|
+
|
|
241
239
|
<color name="header" value="#FFFFFF"/>
|
|
242
240
|
|
|
243
241
|
<color name="tab-selected" value="#a5b6c6" link="#000000" vlink="#000000" hlink="#000000"/>
|
|
@@ -266,8 +264,8 @@ which will be used to configure the chosen Forrest skin.
|
|
|
266
264
|
<color name="code" value="#a5b6c6"/>
|
|
267
265
|
|
|
268
266
|
<color name="footer" value="#a5b6c6"/>
|
|
269
|
-
|
|
270
|
-
<!-- Color group: Collabnet
|
|
267
|
+
|
|
268
|
+
<!-- Color group: Collabnet
|
|
271
269
|
|
|
272
270
|
<color name="header" value="#003366"/>
|
|
273
271
|
|
|
@@ -297,6 +295,8 @@ which will be used to configure the chosen Forrest skin.
|
|
|
297
295
|
<color name="code" value="#003366"/>
|
|
298
296
|
|
|
299
297
|
<color name="footer" value="#ffffff"/>
|
|
298
|
+
|
|
299
|
+
-->
|
|
300
300
|
|
|
301
301
|
<!-- Color group: Lenya using pelt-->
|
|
302
302
|
<!--
|
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/id3'
|
|
17
|
+
require 'test/unit'
|
|
18
|
+
|
|
19
|
+
DATA_LABELS = [ 'city', 'age_range', 'gender', 'marketing_target' ]
|
|
20
|
+
|
|
21
|
+
DATA_SET = [ ['New York', '<30', 'M', 'Y'],
|
|
22
|
+
['Chicago', '<30', 'M', 'Y'],
|
|
23
|
+
['Chicago', '<30', 'F', 'Y'],
|
|
24
|
+
['New York', '<30', 'M', 'Y'],
|
|
25
|
+
['New York', '<30', 'M', 'Y'],
|
|
26
|
+
['Chicago', '[30-50)', 'M', 'Y'],
|
|
27
|
+
['New York', '[30-50)', 'F', 'N'],
|
|
28
|
+
['Chicago', '[30-50)', 'F', 'Y'],
|
|
29
|
+
['New York', '[30-50)', 'F', 'N'],
|
|
30
|
+
['Chicago', '[50-80]', 'M', 'N'],
|
|
31
|
+
['New York', '[50-80]', 'F', 'N'],
|
|
32
|
+
['New York', '[50-80]', 'M', 'N'],
|
|
33
|
+
['Chicago', '[50-80]', 'M', 'N'],
|
|
34
|
+
['New York', '[50-80]', 'F', 'N'],
|
|
35
|
+
['Chicago', '>80', 'F', 'Y']
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
SPLIT_DATA_SET_BY_CITY = [ [
|
|
39
|
+
["New York", "<30", "M", "Y"],
|
|
40
|
+
["New York", "<30", "M", "Y"],
|
|
41
|
+
["New York", "<30", "M", "Y"],
|
|
42
|
+
["New York", "[30-50)", "F", "N"],
|
|
43
|
+
["New York", "[30-50)", "F", "N"],
|
|
44
|
+
["New York", "[50-80]", "F", "N"],
|
|
45
|
+
["New York", "[50-80]", "M", "N"],
|
|
46
|
+
["New York", "[50-80]", "F", "N"]],
|
|
47
|
+
[
|
|
48
|
+
["Chicago", "<30", "M", "Y"],
|
|
49
|
+
["Chicago", "<30", "F", "Y"],
|
|
50
|
+
["Chicago", "[30-50)", "M", "Y"],
|
|
51
|
+
["Chicago", "[30-50)", "F", "Y"],
|
|
52
|
+
["Chicago", "[50-80]", "M", "N"],
|
|
53
|
+
["Chicago", "[50-80]", "M", "N"],
|
|
54
|
+
["Chicago", ">80", "F", "Y"]]
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
SPLIT_DATA_SET_BY_AGE = [ [
|
|
58
|
+
["New York", "<30", "M", "Y"],
|
|
59
|
+
["Chicago", "<30", "M", "Y"],
|
|
60
|
+
["Chicago", "<30", "F", "Y"],
|
|
61
|
+
["New York", "<30", "M", "Y"],
|
|
62
|
+
["New York", "<30", "M", "Y"]],
|
|
63
|
+
[
|
|
64
|
+
["Chicago", "[30-50)", "M", "Y"],
|
|
65
|
+
["New York", "[30-50)", "F", "N"],
|
|
66
|
+
["Chicago", "[30-50)", "F", "Y"],
|
|
67
|
+
["New York", "[30-50)", "F", "N"]],
|
|
68
|
+
[
|
|
69
|
+
["Chicago", "[50-80]", "M", "N"],
|
|
70
|
+
["New York", "[50-80]", "F", "N"],
|
|
71
|
+
["New York", "[50-80]", "M", "N"],
|
|
72
|
+
["Chicago", "[50-80]", "M", "N"],
|
|
73
|
+
["New York", "[50-80]", "F", "N"]],
|
|
74
|
+
[
|
|
75
|
+
["Chicago", ">80", "F", "Y"]]
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
EXPECTED_RULES_STRING =
|
|
79
|
+
"if age_range=='<30' then marketing_target='Y'\n"+
|
|
80
|
+
"elsif age_range=='[30-50)' and city=='Chicago' then marketing_target='Y'\n"+
|
|
81
|
+
"elsif age_range=='[30-50)' and city=='New York' then marketing_target='N'\n"+
|
|
82
|
+
"elsif age_range=='[50-80]' then marketing_target='N'\n"+
|
|
83
|
+
"elsif age_range=='>80' then marketing_target='Y'\n"+
|
|
84
|
+
"else raise 'There was not enough information during training to do a proper induction for this data element' end"
|
|
85
|
+
|
|
86
|
+
Ai4r::Classifiers::ID3.send(:public, *Ai4r::Classifiers::ID3.protected_instance_methods)
|
|
87
|
+
Ai4r::Classifiers::ID3.send(:public, *Ai4r::Classifiers::ID3.private_instance_methods)
|
|
88
|
+
|
|
89
|
+
include Ai4r::Classifiers
|
|
90
|
+
|
|
91
|
+
class ID3Test < Test::Unit::TestCase
|
|
92
|
+
|
|
93
|
+
def test_log2
|
|
94
|
+
assert_equal 1.0, ID3.log2(2)
|
|
95
|
+
assert_equal 0.0, ID3.log2(0)
|
|
96
|
+
assert 1.585 - ID3.log2(3) < 0.001
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def test_sum
|
|
100
|
+
assert_equal 28, ID3.sum([5, 0, 22, 1])
|
|
101
|
+
assert_equal 0, ID3.sum([])
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_data_labels
|
|
105
|
+
id3 = ID3.new.build(DATA_SET)
|
|
106
|
+
expected_default = [ 'attribute_1', 'attribute_2', 'attribute_3', 'class_value' ]
|
|
107
|
+
assert_equal(expected_default, id3.data_labels)
|
|
108
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
109
|
+
assert_equal(DATA_LABELS, id3.data_labels)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_domain
|
|
113
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
114
|
+
expected_domain = [["New York", "Chicago"], ["<30", "[30-50)", "[50-80]", ">80"], ["M", "F"], ["Y", "N"]]
|
|
115
|
+
assert_equal expected_domain, id3.domain(DATA_SET)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_grid
|
|
119
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
120
|
+
expected_grid = [[3, 5], [5, 2]]
|
|
121
|
+
domain = id3.domain(DATA_SET)
|
|
122
|
+
assert_equal expected_grid, id3.freq_grid(0, DATA_SET, domain)
|
|
123
|
+
expected_grid = [[5, 0], [2, 2], [0, 5], [1, 0]]
|
|
124
|
+
assert_equal expected_grid, id3.freq_grid(1, DATA_SET, domain)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def test_entropy
|
|
128
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
129
|
+
expected_entropy = 0.9118
|
|
130
|
+
domain = id3.domain(DATA_SET)
|
|
131
|
+
freq_grid = id3.freq_grid(0, DATA_SET, domain)
|
|
132
|
+
assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
|
|
133
|
+
expected_entropy = 0.2667
|
|
134
|
+
freq_grid = id3.freq_grid(1, DATA_SET, domain)
|
|
135
|
+
assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
|
|
136
|
+
expected_entropy = 0.9688
|
|
137
|
+
freq_grid = id3.freq_grid(2, DATA_SET, domain)
|
|
138
|
+
assert expected_entropy - id3.entropy(freq_grid, DATA_SET.length) < 0.0001
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_min_entropy_index
|
|
142
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
143
|
+
domain = id3.domain(DATA_SET)
|
|
144
|
+
assert_equal 1, id3.min_entropy_index(DATA_SET, domain)
|
|
145
|
+
assert_equal 0, id3.min_entropy_index(DATA_SET, domain, [1])
|
|
146
|
+
assert_equal 2, id3.min_entropy_index(DATA_SET, domain, [1, 0])
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def test_split_data_examples
|
|
150
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
151
|
+
domain = id3.domain(DATA_SET)
|
|
152
|
+
res = id3.split_data_examples(DATA_SET, domain, 0)
|
|
153
|
+
assert_equal(SPLIT_DATA_SET_BY_CITY, res)
|
|
154
|
+
res = id3.split_data_examples(DATA_SET, domain, 1)
|
|
155
|
+
assert_equal(SPLIT_DATA_SET_BY_AGE, res)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_most_freq
|
|
159
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
160
|
+
domain = id3.domain(DATA_SET)
|
|
161
|
+
assert_equal 'Y', id3.most_freq(DATA_SET, domain)
|
|
162
|
+
assert_equal 'Y', id3.most_freq(SPLIT_DATA_SET_BY_AGE[3], domain)
|
|
163
|
+
assert_equal 'N', id3.most_freq(SPLIT_DATA_SET_BY_AGE[2], domain)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_to_s
|
|
167
|
+
assert_equal [["marketing_target='N'"]], CategoryNode.new('marketing_target', 'N').get_rules
|
|
168
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
169
|
+
assert_equal EXPECTED_RULES_STRING, id3.to_s
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def test_eval
|
|
173
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
174
|
+
#if age_range='<30' then marketing_target='Y'
|
|
175
|
+
assert_equal 'Y', id3.eval(['New York', '<30', 'F'])
|
|
176
|
+
assert_equal 'Y', id3.eval(['Chicago', '<30', 'M'])
|
|
177
|
+
#if age_range='[30-50)' and city='Chicago' then marketing_target='Y'
|
|
178
|
+
assert_equal 'Y', id3.eval(['Chicago', '[30-50)', 'F'])
|
|
179
|
+
assert_equal 'Y', id3.eval(['Chicago', '[30-50)', 'M'])
|
|
180
|
+
#if age_range='[30-50)' and city='New York' then marketing_target='N'
|
|
181
|
+
assert_equal 'N', id3.eval(['New York', '[30-50)', 'F'])
|
|
182
|
+
assert_equal 'N', id3.eval(['New York', '[30-50)', 'M'])
|
|
183
|
+
#if age_range='[50-80]' then marketing_target='N'
|
|
184
|
+
assert_equal 'N', id3.eval(['New York', '[50-80]', 'F'])
|
|
185
|
+
assert_equal 'N', id3.eval(['Chicago', '[50-80]', 'M'])
|
|
186
|
+
#if age_range='>80' then marketing_target='Y'
|
|
187
|
+
assert_equal 'Y', id3.eval(['New York', '>80', 'M'])
|
|
188
|
+
assert_equal 'Y', id3.eval(['Chicago', '>80', 'F'])
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def test_rules_eval
|
|
192
|
+
id3 = ID3.new.build(DATA_SET, DATA_LABELS)
|
|
193
|
+
#if age_range='<30' then marketing_target='Y'
|
|
194
|
+
age_range = '<30'
|
|
195
|
+
marketing_target = nil
|
|
196
|
+
eval id3.to_s
|
|
197
|
+
assert_equal 'Y', marketing_target
|
|
198
|
+
#if age_range='[30-50)' and city='New York' then marketing_target='N'
|
|
199
|
+
age_range='[30-50)'
|
|
200
|
+
city='New York'
|
|
201
|
+
eval id3.to_s
|
|
202
|
+
assert_equal 'N', marketing_target
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
2
|
+
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/one_r'
|
|
5
|
+
|
|
6
|
+
class OneRTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
include Ai4r::Classifiers
|
|
9
|
+
|
|
10
|
+
@@data_examples = [ ['New York', '<30', 'M', 'Y'],
|
|
11
|
+
['Chicago', '<30', 'M', 'Y'],
|
|
12
|
+
['New York', '<30', 'M', 'Y'],
|
|
13
|
+
['New York', '[30-50)', 'F', 'N'],
|
|
14
|
+
['Chicago', '[30-50)', 'F', 'Y'],
|
|
15
|
+
['New York', '[30-50)', 'F', 'N'],
|
|
16
|
+
['Chicago', '[50-80]', 'M', 'N']
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
@@data_labels = [ 'city', 'age_range', 'gender', 'marketing_target' ]
|
|
20
|
+
|
|
21
|
+
def test_build
|
|
22
|
+
assert_raise(ArgumentError) { OneR.new.build(nil) }
|
|
23
|
+
assert_raise(ArgumentError) { OneR.new.build([]) }
|
|
24
|
+
classifier = OneR.new.build(@@data_examples)
|
|
25
|
+
assert_not_nil(classifier.data_labels)
|
|
26
|
+
assert_not_nil(classifier.rule)
|
|
27
|
+
assert_equal("attribute_1", classifier.data_labels.first)
|
|
28
|
+
assert_equal("class_value", classifier.data_labels.last)
|
|
29
|
+
classifier = OneR.new.build(@@data_examples, @@data_labels)
|
|
30
|
+
assert_not_nil(classifier.data_labels)
|
|
31
|
+
assert_not_nil(classifier.rule)
|
|
32
|
+
assert_equal("city", classifier.data_labels.first)
|
|
33
|
+
assert_equal("marketing_target", classifier.data_labels.last)
|
|
34
|
+
assert_equal(1, classifier.rule[:attr_index])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_eval
|
|
38
|
+
classifier = OneR.new.build(@@data_examples)
|
|
39
|
+
assert_equal("Y", classifier.eval(['New York', '<30', 'M']))
|
|
40
|
+
assert_equal("N", classifier.eval(['New York', '[30-50)', 'M']))
|
|
41
|
+
assert_equal("N", classifier.eval(['Chicago', '[50-80]', 'M']))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_to_s
|
|
45
|
+
classifier = OneR.new.build(@@data_examples, @@data_labels)
|
|
46
|
+
marketing_target = nil
|
|
47
|
+
age_range = nil
|
|
48
|
+
eval(classifier.to_s)
|
|
49
|
+
assert_nil(marketing_target)
|
|
50
|
+
age_range = '<30'
|
|
51
|
+
eval(classifier.to_s)
|
|
52
|
+
assert_equal("Y", marketing_target)
|
|
53
|
+
age_range = '[30-50)'
|
|
54
|
+
eval(classifier.to_s)
|
|
55
|
+
assert_equal("N", marketing_target)
|
|
56
|
+
age_range = '[50-80]'
|
|
57
|
+
eval(classifier.to_s)
|
|
58
|
+
assert_equal("N", marketing_target)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
2
|
+
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require File.dirname(__FILE__) + '/../../lib/ai4r/classifiers/prism'
|
|
5
|
+
|
|
6
|
+
Ai4r::Classifiers::Prism.send(:public, *Ai4r::Classifiers::Prism.protected_instance_methods)
|
|
7
|
+
Ai4r::Classifiers::Prism.send(:public, *Ai4r::Classifiers::Prism.private_instance_methods)
|
|
8
|
+
|
|
9
|
+
class PrismTest < Test::Unit::TestCase
|
|
10
|
+
|
|
11
|
+
include Ai4r::Classifiers
|
|
12
|
+
|
|
13
|
+
@@data_examples = [ ['New York', '<30', 'M', 'Y'],
|
|
14
|
+
['Chicago', '<30', 'M', 'Y'],
|
|
15
|
+
['Chicago', '<30', 'F', 'Y'],
|
|
16
|
+
['New York', '<30', 'M', 'Y'],
|
|
17
|
+
['New York', '<30', 'M', 'Y'],
|
|
18
|
+
['Chicago', '[30-50)', 'M', 'Y'],
|
|
19
|
+
['New York', '[30-50)', 'F', 'N'],
|
|
20
|
+
['Chicago', '[30-50)', 'F', 'Y'],
|
|
21
|
+
['New York', '[30-50)', 'F', 'N'],
|
|
22
|
+
['Chicago', '[50-80]', 'M', 'N'],
|
|
23
|
+
['New York', '[50-80]', 'F', 'N'],
|
|
24
|
+
['New York', '[50-80]', 'M', 'N'],
|
|
25
|
+
['Chicago', '[50-80]', 'M', 'N'],
|
|
26
|
+
['New York', '[50-80]', 'F', 'N'],
|
|
27
|
+
['Chicago', '>80', 'F', 'Y']
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
@@data_labels = [ 'city', 'age_range', 'gender', 'marketing_target' ]
|
|
31
|
+
|
|
32
|
+
def test_build
|
|
33
|
+
assert_raise(ArgumentError) { Prism.new.build(nil) }
|
|
34
|
+
assert_raise(ArgumentError) { Prism.new.build([]) }
|
|
35
|
+
classifier = Prism.new.build(@@data_examples)
|
|
36
|
+
assert_not_nil(classifier.data_labels)
|
|
37
|
+
assert_not_nil(classifier.rules)
|
|
38
|
+
assert_equal("attribute_1", classifier.data_labels.first)
|
|
39
|
+
assert_equal("class_value", classifier.data_labels.last)
|
|
40
|
+
classifier = Prism.new.build(@@data_examples, @@data_labels)
|
|
41
|
+
assert_not_nil(classifier.data_labels)
|
|
42
|
+
assert_not_nil(classifier.rules)
|
|
43
|
+
assert_equal("city", classifier.data_labels.first)
|
|
44
|
+
assert_equal("marketing_target", classifier.data_labels.last)
|
|
45
|
+
assert !classifier.rules.empty?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_eval
|
|
49
|
+
classifier = Prism.new.build(@@data_examples)
|
|
50
|
+
@@data_examples.each do |data|
|
|
51
|
+
assert_equal(data.last, classifier.eval(data[0...-1]))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_to_s
|
|
56
|
+
classifier = Prism.new.build(@@data_examples, @@data_labels)
|
|
57
|
+
marketing_target = nil
|
|
58
|
+
age_range = nil
|
|
59
|
+
city = 'Chicago'
|
|
60
|
+
eval(classifier.to_s)
|
|
61
|
+
age_range = '<30'
|
|
62
|
+
eval(classifier.to_s)
|
|
63
|
+
assert_equal("Y", marketing_target)
|
|
64
|
+
age_range = '[30-50)'
|
|
65
|
+
eval(classifier.to_s)
|
|
66
|
+
assert_equal("Y", marketing_target)
|
|
67
|
+
age_range = '[30-50)'
|
|
68
|
+
city = 'New York'
|
|
69
|
+
eval(classifier.to_s)
|
|
70
|
+
assert_equal("N", marketing_target)
|
|
71
|
+
age_range = '[50-80]'
|
|
72
|
+
eval(classifier.to_s)
|
|
73
|
+
assert_equal("N", marketing_target)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_matches_conditions
|
|
77
|
+
classifier = Prism.new
|
|
78
|
+
classifier.data_labels = @@data_labels
|
|
79
|
+
assert classifier.matches_conditions(['New York', '<30', 'M', 'Y'], {"age_range" => "<30"})
|
|
80
|
+
assert !classifier.matches_conditions(['New York', '<30', 'M', 'Y'], {"age_range" => "[50-80]"})
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|