Class: Idhja22::Tree

Inherits:
BinaryClassifier show all
Defined in:
lib/idhja22/tree.rb

Overview

The main entry class for a training, viewing and evaluating a decision tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BinaryClassifier

train, train_and_validate, train_and_validate_from_csv, train_from_csv, #validate

Instance Attribute Details

#rootObject

Returns the value of attribute root.



6
7
8
# File 'lib/idhja22/tree.rb', line 6

def root
  @root
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/idhja22/tree.rb', line 21

def ==(other)
  return self.root == other.root
end

#evaluate(query) ⇒ Object



25
26
27
# File 'lib/idhja22/tree.rb', line 25

def evaluate query
  @root.evaluate(query)
end

#get_rulesObject



16
17
18
19
# File 'lib/idhja22/tree.rb', line 16

def get_rules
  rules = root.get_rules
  "if " + rules.join("\nelsif ")
end

#train(dataset, attributes_available) ⇒ Object



10
11
12
13
14
# File 'lib/idhja22/tree.rb', line 10

def train(dataset, attributes_available)
  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)
  @root = Node.build_node(dataset, attributes_available, 0)
  return self
end