Class: Idhja22::LeafNode
Instance Attribute Summary collapse
-
#category_label ⇒ Object
readonly
Returns the value of attribute category_label.
-
#probability ⇒ Object
readonly
Returns the value of attribute probability.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#cleanup_children! ⇒ Object
no-op method - a leaf node has no children by definition.
- #evaluate(query) ⇒ Object
- #get_rules ⇒ Object
-
#initialize(probability, category_label) ⇒ LeafNode
constructor
A new instance of LeafNode.
- #leaves ⇒ Object
Methods inherited from Node
Constructor Details
#initialize(probability, category_label) ⇒ LeafNode
Returns a new instance of LeafNode.
151 152 153 154 |
# File 'lib/idhja22/tree/node.rb', line 151 def initialize(probability, category_label) @probability = probability @category_label = category_label end |
Instance Attribute Details
#category_label ⇒ Object (readonly)
Returns the value of attribute category_label.
143 144 145 |
# File 'lib/idhja22/tree/node.rb', line 143 def category_label @category_label end |
#probability ⇒ Object (readonly)
Returns the value of attribute probability.
143 144 145 |
# File 'lib/idhja22/tree/node.rb', line 143 def probability @probability end |
Class Method Details
.build(dataset, prior) ⇒ Object
145 146 147 |
# File 'lib/idhja22/tree/node.rb', line 145 def build(dataset, prior) return new(dataset.m_estimate(prior), dataset.category_label) end |
Instance Method Details
#==(other) ⇒ Object
160 161 162 |
# File 'lib/idhja22/tree/node.rb', line 160 def ==(other) return super && self.probability == other.probability && self.category_label == other.category_label end |
#cleanup_children! ⇒ Object
no-op method - a leaf node has no children by definition
174 175 176 |
# File 'lib/idhja22/tree/node.rb', line 174 def cleanup_children! end |
#evaluate(query) ⇒ Object
164 165 166 167 |
# File 'lib/idhja22/tree/node.rb', line 164 def evaluate(query) raise Idhja22::Dataset::Datum::UnknownCategoryLabel, "expected category label for query is #{query.category_label} but node is using #{self.category_label}" unless query.category_label == self.category_label return probability end |
#get_rules ⇒ Object
156 157 158 |
# File 'lib/idhja22/tree/node.rb', line 156 def get_rules ["then chance of #{category_label} = #{probability.round(2)}"] end |
#leaves ⇒ Object
169 170 171 |
# File 'lib/idhja22/tree/node.rb', line 169 def leaves return [self] end |