idhja22 1.1.1 → 1.2.0
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/lib/idhja22/tree/node.rb +5 -4
- data/lib/idhja22/version.rb +1 -1
- data/spec/node/decision_node_spec.rb +18 -2
- data/spec/tree_spec.rb +1 -1
- data/spec/version_spec.rb +1 -1
- metadata +3 -3
data/lib/idhja22/tree/node.rb
CHANGED
@@ -52,13 +52,13 @@ module Idhja22
|
|
52
52
|
end
|
53
53
|
|
54
54
|
class DecisionNode < Node
|
55
|
-
|
55
|
+
attr_accessor :branches, :decision_attribute, :default_probability
|
56
56
|
|
57
57
|
class << self
|
58
58
|
def build(dataset, attributes_available, depth, parent_probability=nil)
|
59
59
|
data_split, best_attribute = best_attribute(dataset, attributes_available)
|
60
60
|
|
61
|
-
output_node = new(best_attribute)
|
61
|
+
output_node = new(best_attribute, parent_probability)
|
62
62
|
|
63
63
|
data_split.each do |value, dataset|
|
64
64
|
node = Node.build_node(dataset, attributes_available-[best_attribute], depth+1, dataset.m_estimate(parent_probability))
|
@@ -72,9 +72,10 @@ module Idhja22
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
def initialize(decision_attribute)
|
75
|
+
def initialize(decision_attribute, default_probability = nil)
|
76
76
|
@decision_attribute = decision_attribute
|
77
77
|
@branches = {}
|
78
|
+
@default_probability = (default_probability || Idhja22.config.default_probability)
|
78
79
|
end
|
79
80
|
|
80
81
|
def add_branch(attr_value, node)
|
@@ -108,7 +109,7 @@ module Idhja22
|
|
108
109
|
def evaluate(query)
|
109
110
|
queried_value = query[self.decision_attribute]
|
110
111
|
branch = self.branches[queried_value]
|
111
|
-
|
112
|
+
return default_probability if branch.nil?
|
112
113
|
branch.evaluate(query)
|
113
114
|
end
|
114
115
|
|
data/lib/idhja22/version.rb
CHANGED
@@ -94,9 +94,9 @@ describe Idhja22::DecisionNode do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
context 'unknown attribute value' do
|
97
|
-
it 'should
|
97
|
+
it 'should return default probability value' do
|
98
98
|
query = Idhja22::Dataset::Datum.new(['c', 'a'], ['3', '4'], 'C')
|
99
|
-
|
99
|
+
@simple_decision_node.evaluate(query).should == 0.5
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
@@ -202,4 +202,20 @@ describe Idhja22::DecisionNode do
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
end
|
205
|
+
|
206
|
+
describe '.new' do
|
207
|
+
it 'should set instance variables' do
|
208
|
+
dn = Idhja22::DecisionNode.new('attr_label', 0.7)
|
209
|
+
dn.decision_attribute.should == 'attr_label'
|
210
|
+
dn.default_probability.should == 0.7
|
211
|
+
dn.branches.should == {}
|
212
|
+
end
|
213
|
+
|
214
|
+
context 'without provided default probability' do
|
215
|
+
it 'should set default to config default' do
|
216
|
+
dn = Idhja22::DecisionNode.new('attr_label')
|
217
|
+
dn.default_probability.should == 0.5
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
205
221
|
end
|
data/spec/tree_spec.rb
CHANGED
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -176,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
segments:
|
178
178
|
- 0
|
179
|
-
hash:
|
179
|
+
hash: 144077394884408186
|
180
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
181
|
none: false
|
182
182
|
requirements:
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash:
|
188
|
+
hash: 144077394884408186
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project:
|
191
191
|
rubygems_version: 1.8.24
|