ruby-band 0.1.11
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/.travis.yml +3 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +119 -0
- data/Jarfile +9 -0
- data/Jarfile.lock +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +321 -0
- data/README.rdoc +70 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/band_server/client.rb +35 -0
- data/band_server/client_alt.rb +35 -0
- data/band_server/first_dataset.csv +15 -0
- data/band_server/second_dataset.csv +15 -0
- data/band_server/simple_server.rb +90 -0
- data/band_server/third_dataset.csv +15 -0
- data/band_server/uploads/first_dataset.csv +15 -0
- data/band_server/uploads/second_dataset.csv +15 -0
- data/band_server/uploads/third_dataset.csv +15 -0
- data/bin/ruby-band +83 -0
- data/ext/mkrf_conf.rb +74 -0
- data/features/create_dataset.feature +12 -0
- data/features/step_definitions/create_dataset.rb +39 -0
- data/features/step_definitions/weka_classifiers.rb +43 -0
- data/features/step_definitions/weka_clustering.rb +34 -0
- data/features/step_definitions/weka_filters.rb +32 -0
- data/features/step_definitions/weka_parsers.rb +46 -0
- data/features/step_definitions/weka_pipeline.rb +41 -0
- data/features/support/env.rb +3 -0
- data/features/weka_classifiers.feature +16 -0
- data/features/weka_clustering.feature +15 -0
- data/features/weka_filters.feature +12 -0
- data/features/weka_parsers.feature +18 -0
- data/features/weka_pipeline.feature +14 -0
- data/lib/ruby-band.rb +12 -0
- data/lib/ruby-band/apache.rb +2 -0
- data/lib/ruby-band/apache/stat/correlation.rb +42 -0
- data/lib/ruby-band/apache/stat/inference.rb +151 -0
- data/lib/ruby-band/apache/stat/regression.rb +22 -0
- data/lib/ruby-band/core.rb +6 -0
- data/lib/ruby-band/core/parser/parser.rb +27 -0
- data/lib/ruby-band/core/type/apache_matrices.rb +35 -0
- data/lib/ruby-band/core/type/attribute.rb +53 -0
- data/lib/ruby-band/core/type/instance.rb +10 -0
- data/lib/ruby-band/core/type/instances.rb +361 -0
- data/lib/ruby-band/core/type/utils.rb +31 -0
- data/lib/ruby-band/weka.rb +14 -0
- data/lib/ruby-band/weka/attribute_selection/attribute_selection_utils.rb +20 -0
- data/lib/ruby-band/weka/attribute_selection/evaluators.rb +58 -0
- data/lib/ruby-band/weka/attribute_selection/search.rb +52 -0
- data/lib/ruby-band/weka/classifiers/bayes/bayes.rb +86 -0
- data/lib/ruby-band/weka/classifiers/bayes/bayes_utils.rb +82 -0
- data/lib/ruby-band/weka/classifiers/evaluation.rb +13 -0
- data/lib/ruby-band/weka/classifiers/functions/functions.rb +177 -0
- data/lib/ruby-band/weka/classifiers/functions/functions_utils.rb +78 -0
- data/lib/ruby-band/weka/classifiers/lazy/lazy.rb +86 -0
- data/lib/ruby-band/weka/classifiers/lazy/lazy_utils.rb +83 -0
- data/lib/ruby-band/weka/classifiers/mi/mi.rb +191 -0
- data/lib/ruby-band/weka/classifiers/mi/mi_utils.rb +80 -0
- data/lib/ruby-band/weka/classifiers/rules/rules.rb +190 -0
- data/lib/ruby-band/weka/classifiers/rules/rules_utils.rb +81 -0
- data/lib/ruby-band/weka/classifiers/trees/trees.rb +110 -0
- data/lib/ruby-band/weka/classifiers/trees/trees_utils.rb +85 -0
- data/lib/ruby-band/weka/clusterers/clusterers.rb +99 -0
- data/lib/ruby-band/weka/clusterers/clusterers_utils.rb +86 -0
- data/lib/ruby-band/weka/db/DatabaseUtils_mysql +280 -0
- data/lib/ruby-band/weka/db/DatabaseUtils_postgresql +594 -0
- data/lib/ruby-band/weka/db/db.rb +74 -0
- data/lib/ruby-band/weka/filters/supervised/attribute/attribute.rb +55 -0
- data/lib/ruby-band/weka/filters/supervised/instance/instance.rb +17 -0
- data/lib/ruby-band/weka/filters/supervised/supervised_utils.rb +38 -0
- data/lib/ruby-band/weka/filters/unsupervised/attribute/attribute.rb +90 -0
- data/lib/ruby-band/weka/filters/unsupervised/instance/instance.rb +48 -0
- data/lib/ruby-band/weka/filters/unsupervised/unsupervised_utils.rb +38 -0
- data/resources/ReutersGrain-test.arff +611 -0
- data/resources/ReutersGrain-train.arff +1561 -0
- data/resources/weather.csv +15 -0
- data/resources/weather.numeric.arff +23 -0
- data/ruby-band.gemspec +178 -0
- data/spec/ruby-band_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/test/helper.rb +18 -0
- data/test/test_apacheCorrelation.rb +22 -0
- data/test/test_apacheInference.rb +46 -0
- data/test/test_ruby-band.rb +9 -0
- metadata +426 -0
@@ -0,0 +1,190 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'rules_utils'
|
3
|
+
|
4
|
+
module Weka
|
5
|
+
module Classifier
|
6
|
+
module Rules
|
7
|
+
java_import "weka.classifiers.rules.DecisionTable"
|
8
|
+
java_import "weka.classifiers.rules.DTNB"
|
9
|
+
java_import "weka.classifiers.rules.JRip"
|
10
|
+
java_import "weka.classifiers.rules.M5Rules"
|
11
|
+
java_import "weka.classifiers.rules.NNge"
|
12
|
+
java_import "weka.classifiers.rules.OneR"
|
13
|
+
java_import "weka.classifiers.rules.PART"
|
14
|
+
java_import "weka.classifiers.rules.Prism"
|
15
|
+
java_import "weka.classifiers.rules.Ridor"
|
16
|
+
java_import "weka.classifiers.rules.Rule"
|
17
|
+
java_import "weka.classifiers.rules.RuleStats"
|
18
|
+
java_import "weka.classifiers.rules.ZeroR"
|
19
|
+
|
20
|
+
class DecisionTable
|
21
|
+
include Rules_utils
|
22
|
+
class Base < DecisionTable
|
23
|
+
def initialize(&block)
|
24
|
+
super
|
25
|
+
if block_given?
|
26
|
+
init_instance_classifier(&block)
|
27
|
+
else
|
28
|
+
init_classifier
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class DTNB
|
35
|
+
include Rules_utils
|
36
|
+
class Base < DTNB
|
37
|
+
def initialize(&block)
|
38
|
+
super
|
39
|
+
if block_given?
|
40
|
+
init_instance_classifier(&block)
|
41
|
+
else
|
42
|
+
init_classifier
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class JRip
|
49
|
+
include Rules_utils
|
50
|
+
class Base < JRip
|
51
|
+
def initialize(&block)
|
52
|
+
super
|
53
|
+
if block_given?
|
54
|
+
init_instance_classifier(&block)
|
55
|
+
else
|
56
|
+
init_classifier
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class M5Rules
|
63
|
+
include Rules_utils
|
64
|
+
class Base < M5Rules
|
65
|
+
def initialize(&block)
|
66
|
+
super
|
67
|
+
if block_given?
|
68
|
+
init_instance_classifier(&block)
|
69
|
+
else
|
70
|
+
init_classifier
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class NNge
|
77
|
+
include Rules_utils
|
78
|
+
class Base < NNge
|
79
|
+
def initialize(&block)
|
80
|
+
super
|
81
|
+
if block_given?
|
82
|
+
init_instance_classifier(&block)
|
83
|
+
else
|
84
|
+
init_classifier
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class OneR
|
91
|
+
include Rules_utils
|
92
|
+
class Base < OneR
|
93
|
+
def initialize(&block)
|
94
|
+
super
|
95
|
+
if block_given?
|
96
|
+
init_instance_classifier(&block)
|
97
|
+
else
|
98
|
+
init_classifier
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class PART
|
105
|
+
include Rules_utils
|
106
|
+
class Base < PART
|
107
|
+
def initialize(&block)
|
108
|
+
super
|
109
|
+
if block_given?
|
110
|
+
init_instance_classifier(&block)
|
111
|
+
else
|
112
|
+
init_classifier
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class Prism
|
119
|
+
include Rules_utils
|
120
|
+
class Base < Prism
|
121
|
+
def initialize(&block)
|
122
|
+
super
|
123
|
+
if block_given?
|
124
|
+
init_instance_classifier(&block)
|
125
|
+
else
|
126
|
+
init_classifier
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
class Ridor
|
133
|
+
include Rules_utils
|
134
|
+
class Base < Ridor
|
135
|
+
def initialize(&block)
|
136
|
+
super
|
137
|
+
if block_given?
|
138
|
+
init_instance_classifier(&block)
|
139
|
+
else
|
140
|
+
init_classifier
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
class Rule
|
147
|
+
include Rules_utils
|
148
|
+
class Base < Rule
|
149
|
+
def initialize(&block)
|
150
|
+
super
|
151
|
+
if block_given?
|
152
|
+
init_instance_classifier(&block)
|
153
|
+
else
|
154
|
+
init_classifier
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
class RuleStats
|
161
|
+
include Rules_utils
|
162
|
+
class Base < RuleStats
|
163
|
+
def initialize(&block)
|
164
|
+
super
|
165
|
+
if block_given?
|
166
|
+
init_instance_classifier(&block)
|
167
|
+
else
|
168
|
+
init_classifier
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
class ZeroR
|
175
|
+
include Rules_utils
|
176
|
+
class Base < ZeroR
|
177
|
+
def initialize(&block)
|
178
|
+
super
|
179
|
+
if block_given?
|
180
|
+
init_instance_classifier(&block)
|
181
|
+
else
|
182
|
+
init_classifier
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
#This module is used by the 'rules' classifiers from 'rules.rb'
|
2
|
+
#to inherit the following methods (instance and class methods)
|
3
|
+
module Rules_utils
|
4
|
+
java_import "weka.core.Utils"
|
5
|
+
|
6
|
+
def init_rules
|
7
|
+
set_options(self.class.options) if self.class.options
|
8
|
+
self.class.data.setClassIndex(self.class.class_index) if self.class.class_index
|
9
|
+
buildClassifier(self.class.data)
|
10
|
+
end
|
11
|
+
|
12
|
+
#Instance methods list
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
def init_instance_classifier(&block)
|
18
|
+
self.instance_eval(&block)
|
19
|
+
@dataset.setClassIndex(@class_index)
|
20
|
+
build_classifier(@dataset)
|
21
|
+
end
|
22
|
+
|
23
|
+
#Set data for instance classifier
|
24
|
+
#ARGV
|
25
|
+
# data -> an Instances object
|
26
|
+
def set_data(data)
|
27
|
+
@dataset = data
|
28
|
+
end
|
29
|
+
|
30
|
+
#Set a class index for the input dataset
|
31
|
+
def set_class_index(class_index)
|
32
|
+
@class_index = class_index
|
33
|
+
end
|
34
|
+
|
35
|
+
#Set options for the selected classifier
|
36
|
+
#ARGS:
|
37
|
+
#options -> a String, i.e. "-K 3"
|
38
|
+
def set_options(options)
|
39
|
+
options_inst = Utils.splitOptions(options)
|
40
|
+
setOptions(options_inst)
|
41
|
+
end
|
42
|
+
|
43
|
+
def list_options
|
44
|
+
listOptions.map {|key| "#{key.synopsis} #{key.description}"}.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
def description
|
48
|
+
puts globalInfo
|
49
|
+
end
|
50
|
+
|
51
|
+
# perform crossvalidation on a trained classifier
|
52
|
+
#ARGV:
|
53
|
+
#fold -> 'int' value
|
54
|
+
def cross_validate(fold)
|
55
|
+
if self.class.data
|
56
|
+
eval = Weka::Classifier::Evaluation.new self.class.data
|
57
|
+
eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
|
58
|
+
eval.summary
|
59
|
+
else
|
60
|
+
eval = Weka::Classifier::Evaluation.new @dataset
|
61
|
+
eval.crossValidateModel(self.class.ancestors[1].new, @dataset, fold.to_java(:int), Random.new(1))
|
62
|
+
eval.summary
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#Class methods module
|
67
|
+
module ClassMethods
|
68
|
+
|
69
|
+
def self.classifier_attr_accessor(*args)
|
70
|
+
args.each do |arg|
|
71
|
+
#Here's the getter
|
72
|
+
self.class_eval("def #{arg};@#{arg};end")
|
73
|
+
#Here's the setter
|
74
|
+
self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
classifier_attr_accessor :options,:data,:class_index
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
require 'trees_utils'
|
3
|
+
|
4
|
+
module Weka
|
5
|
+
module Classifier
|
6
|
+
#This module contains classifiers from the 'weka.classifiers.trees' package
|
7
|
+
module Trees
|
8
|
+
java_import 'weka.classifiers.trees.J48'
|
9
|
+
java_import 'weka.classifiers.trees.FT'
|
10
|
+
java_import 'weka.classifiers.trees.RandomForest'
|
11
|
+
java_import 'weka.classifiers.trees.BFTree'
|
12
|
+
java_import 'weka.classifiers.trees.J48graft'
|
13
|
+
java_import 'weka.classifiers.trees.LADTree'
|
14
|
+
java_import 'weka.classifiers.trees.LMT'
|
15
|
+
java_import 'weka.classifiers.trees.M5P'
|
16
|
+
java_import 'weka.classifiers.trees.RandomTree'
|
17
|
+
|
18
|
+
class ADTree
|
19
|
+
include Trees_utils
|
20
|
+
class Base < ADTree
|
21
|
+
def initialize
|
22
|
+
super
|
23
|
+
init_tree
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class BFTree
|
29
|
+
include Trees_utils
|
30
|
+
class Base < BFTree
|
31
|
+
def initialize
|
32
|
+
super
|
33
|
+
init_tree
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class FT
|
39
|
+
include Trees_utils
|
40
|
+
class Base < FT
|
41
|
+
def initialize
|
42
|
+
super
|
43
|
+
init_tree
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class J48
|
49
|
+
include Trees_utils
|
50
|
+
class Base < J48
|
51
|
+
def initialize
|
52
|
+
super
|
53
|
+
init_tree
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class J48graft
|
59
|
+
include Trees_utils
|
60
|
+
class Base < J48graft
|
61
|
+
def initialize
|
62
|
+
super
|
63
|
+
init_tree
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class LMT
|
69
|
+
include Trees_utils
|
70
|
+
class Base < LMT
|
71
|
+
def initialize
|
72
|
+
super
|
73
|
+
init_tree
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class M5P
|
79
|
+
include Trees_utils
|
80
|
+
class Base < M5P
|
81
|
+
def initialize
|
82
|
+
super
|
83
|
+
init_tree
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class RandomForest
|
89
|
+
include Trees_utils
|
90
|
+
class Base < RandomForest
|
91
|
+
def initialize
|
92
|
+
super
|
93
|
+
init_tree
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class RandomTree
|
99
|
+
include Trees_utils
|
100
|
+
class Base < RandomTree
|
101
|
+
def initialize
|
102
|
+
super
|
103
|
+
init_tree
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# This module is used by the 'trees' classifiers from 'trees.rb'
|
2
|
+
# to inherit the following methods (instance and class methods)
|
3
|
+
module Trees_utils
|
4
|
+
java_import "weka.core.Utils"
|
5
|
+
|
6
|
+
def init_tree
|
7
|
+
set_options(self.class.options) if self.class.options
|
8
|
+
self.class.data.setClassIndex(self.class.class_index) if self.class.class_index
|
9
|
+
buildClassifier(self.class.data)
|
10
|
+
end
|
11
|
+
|
12
|
+
#Instance methods list
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
def init_instance_classifier(&block)
|
18
|
+
self.instance_eval(&block)
|
19
|
+
@dataset.setClassIndex(@class_index)
|
20
|
+
build_classifier(@dataset)
|
21
|
+
end
|
22
|
+
|
23
|
+
#Set input data for the selected classifier
|
24
|
+
#ARGV:
|
25
|
+
#data -> an Instances class object
|
26
|
+
def set_data(data)
|
27
|
+
@dataset = data
|
28
|
+
end
|
29
|
+
|
30
|
+
#Set the class index for the input dataset
|
31
|
+
def set_class_index(class_index)
|
32
|
+
@class_index = class_index
|
33
|
+
end
|
34
|
+
|
35
|
+
#Set options for the instance classifier
|
36
|
+
#ARGS:
|
37
|
+
#options -> A String object, i.e. "-K 3"
|
38
|
+
def set_options(options)
|
39
|
+
options_inst = Utils.splitOptions(options)
|
40
|
+
setOptions(options_inst)
|
41
|
+
end
|
42
|
+
|
43
|
+
def list_options
|
44
|
+
listOptions.each {|key| puts "#{key.synopsis} #{key.description}"}
|
45
|
+
end
|
46
|
+
|
47
|
+
#Return a short description for the selected classifier
|
48
|
+
def description
|
49
|
+
puts globalInfo
|
50
|
+
end
|
51
|
+
|
52
|
+
# perform crossvalidation on a trained classifier
|
53
|
+
#ARGV:
|
54
|
+
#fold -> 'int' value
|
55
|
+
def cross_validate(fold)
|
56
|
+
if self.class.data
|
57
|
+
eval = Weka::Classifier::Evaluation.new self.class.data
|
58
|
+
eval.crossValidateModel(self.class.ancestors[2].new, self.class.data, fold.to_java(:int), Random.new(1))
|
59
|
+
eval.summary
|
60
|
+
else
|
61
|
+
eval = Weka::Classifier::Evaluation.new @dataset
|
62
|
+
eval.crossValidateModel(self.class.ancestors[1].new, @dataset, fold.to_java(:int), Random.new(1))
|
63
|
+
eval.summary
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#Class methods module
|
68
|
+
module ClassMethods
|
69
|
+
|
70
|
+
def self.classifier_attr_accessor(*args)
|
71
|
+
args.each do |arg|
|
72
|
+
#Here's the getter
|
73
|
+
self.class_eval("def #{arg};@#{arg};end")
|
74
|
+
#Here's the setter
|
75
|
+
self.class_eval("def set_#{arg}(val);@#{arg}=val;end")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
classifier_attr_accessor :options,:data,:class_index
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|