idhja22 0.14.3 → 0.14.4
Sign up to get free protection for your applications and to get access to all the features.
- data/idhja22.gemspec +2 -0
- data/lib/idhja22/bayes.rb +5 -0
- data/lib/idhja22/config/default.rb +5 -0
- data/lib/idhja22/dataset/tree_methods.rb +2 -2
- data/lib/idhja22/{node.rb → tree/node.rb} +2 -2
- data/lib/idhja22/tree.rb +3 -1
- data/lib/idhja22/version.rb +1 -1
- data/lib/idhja22.rb +17 -4
- data/spec/bayes_spec.rb +5 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/version_spec.rb +1 -1
- metadata +25 -5
data/idhja22.gemspec
CHANGED
@@ -15,12 +15,12 @@ module Idhja22
|
|
15
15
|
|
16
16
|
def entropy
|
17
17
|
total = self.size
|
18
|
-
return 1.0 if total < Idhja22
|
18
|
+
return 1.0 if total < Idhja22.config.min_dataset_size
|
19
19
|
category_counts.values.inject(0.0) { |ent, count| prop = count.to_f/total.to_f; ent-prop*Math.log(prop,2) }
|
20
20
|
end
|
21
21
|
|
22
22
|
def terminating?
|
23
|
-
probability > Idhja22
|
23
|
+
(probability > Idhja22.config.termination_probability) || (probability < (1-Idhja22.config.termination_probability))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -2,7 +2,7 @@ module Idhja22
|
|
2
2
|
class Node
|
3
3
|
class << self
|
4
4
|
def build_node(dataset, attributes_available, depth, parent_probability = nil)
|
5
|
-
if(dataset.size < Idhja22
|
5
|
+
if(dataset.size < Idhja22.config.min_dataset_size)
|
6
6
|
return Idhja22::LeafNode.new(probability_guess(parent_probability, depth), dataset.category_label)
|
7
7
|
end
|
8
8
|
|
@@ -48,7 +48,7 @@ module Idhja22
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def probability_guess(parent_probability, depth)
|
51
|
-
return (parent_probability + (Idhja22
|
51
|
+
return (parent_probability + (Idhja22.config.default_probability-parent_probability)/2**depth)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/idhja22/tree.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "idhja22/tree/node"
|
2
|
+
|
1
3
|
module Idhja22
|
2
4
|
# The main entry class for a training, viewing and evaluating a decision tree.
|
3
5
|
class Tree
|
@@ -34,7 +36,7 @@ module Idhja22
|
|
34
36
|
end
|
35
37
|
|
36
38
|
def initialize(dataset, attributes_available)
|
37
|
-
raise Idhja22::Dataset::InsufficientData, "require at least #{Idhja22
|
39
|
+
raise Idhja22::Dataset::InsufficientData, "require at least #{Idhja22.config.min_dataset_size} data points, only have #{dataset.size} in data set provided" if(dataset.size < Idhja22.config.min_dataset_size)
|
38
40
|
@root = Node.build_node(dataset, attributes_available, 0)
|
39
41
|
end
|
40
42
|
|
data/lib/idhja22/version.rb
CHANGED
data/lib/idhja22.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
|
+
require 'configuration'
|
2
|
+
require 'idhja22/config/default'
|
3
|
+
|
1
4
|
require "idhja22/version"
|
2
5
|
require "idhja22/dataset"
|
3
6
|
require "idhja22/tree"
|
4
|
-
require "idhja22/
|
7
|
+
require "idhja22/bayes"
|
5
8
|
|
6
9
|
module Idhja22
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
+
def self.default_config
|
11
|
+
Configuration.for('default')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure(name)
|
15
|
+
new_config = Configuration.for(name)
|
16
|
+
@cached_config = new_config
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.config
|
20
|
+
@cached_config ||= default_config
|
21
|
+
end
|
22
|
+
|
10
23
|
end
|
data/spec/bayes_spec.rb
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -9,11 +9,11 @@ $: << File.dirname(__FILE__) + '/../lib'
|
|
9
9
|
require 'idhja22'
|
10
10
|
require 'ruby-debug'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
Configuration.for('spec', Idhja22.config) {
|
13
|
+
min_dataset_size 2
|
14
|
+
}
|
16
15
|
|
16
|
+
Idhja22.configure('spec')
|
17
17
|
|
18
18
|
RSpec.configure do |config|
|
19
19
|
|
data/spec/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idhja22
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: configuration
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: Decision Trees
|
111
127
|
email:
|
112
128
|
executables:
|
@@ -124,14 +140,17 @@ files:
|
|
124
140
|
- bin/idhja22
|
125
141
|
- idhja22.gemspec
|
126
142
|
- lib/idhja22.rb
|
143
|
+
- lib/idhja22/bayes.rb
|
144
|
+
- lib/idhja22/config/default.rb
|
127
145
|
- lib/idhja22/dataset.rb
|
128
146
|
- lib/idhja22/dataset/datum.rb
|
129
147
|
- lib/idhja22/dataset/errors.rb
|
130
148
|
- lib/idhja22/dataset/tree_methods.rb
|
131
|
-
- lib/idhja22/node.rb
|
132
149
|
- lib/idhja22/tree.rb
|
150
|
+
- lib/idhja22/tree/node.rb
|
133
151
|
- lib/idhja22/version.rb
|
134
152
|
- spec/another_large_spec_data.csv
|
153
|
+
- spec/bayes_spec.rb
|
135
154
|
- spec/dataset/example_spec.rb
|
136
155
|
- spec/dataset_spec.rb
|
137
156
|
- spec/large_spec_data.csv
|
@@ -154,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
173
|
version: '0'
|
155
174
|
segments:
|
156
175
|
- 0
|
157
|
-
hash:
|
176
|
+
hash: -803768552583374641
|
158
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
178
|
none: false
|
160
179
|
requirements:
|
@@ -163,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
182
|
version: '0'
|
164
183
|
segments:
|
165
184
|
- 0
|
166
|
-
hash:
|
185
|
+
hash: -803768552583374641
|
167
186
|
requirements: []
|
168
187
|
rubyforge_project:
|
169
188
|
rubygems_version: 1.8.24
|
@@ -172,6 +191,7 @@ specification_version: 3
|
|
172
191
|
summary: A gem for creating decision trees
|
173
192
|
test_files:
|
174
193
|
- spec/another_large_spec_data.csv
|
194
|
+
- spec/bayes_spec.rb
|
175
195
|
- spec/dataset/example_spec.rb
|
176
196
|
- spec/dataset_spec.rb
|
177
197
|
- spec/large_spec_data.csv
|