Class: DecisionTree
- Inherits:
-
Object
- Object
- DecisionTree
- Defined in:
- lib/decision_tree.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #decide(features) ⇒ Object
-
#initialize(tree_xml) ⇒ DecisionTree
constructor
A new instance of DecisionTree.
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
#root ⇒ Object (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 |