Class: DecisionTree

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree_xml) ⇒ DecisionTree

Returns a new instance of DecisionTree.



7
8
9
10
# File 'lib/decision_tree.rb', line 7

def initialize(tree_xml)
  @id = tree_xml.attribute('id')
  @root = Node.new(tree_xml.xpath('TreeModel/Node'))
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/decision_tree.rb', line 5

def root
  @root
end

Instance Method Details

#decide(features) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/decision_tree.rb', line 12

def decide(features)
  curr = @root
  while curr.decision == ''
    prev = curr
    curr = step(curr, features)
    return if didnt_step?(curr, prev)
  end

  curr.decision
end