Class: Idhja22::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/idhja22/tree/node.rb

Direct Known Subclasses

DecisionNode, LeafNode

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_node(dataset, attributes_available, depth, prior = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/idhja22/tree/node.rb', line 4

def build_node(dataset, attributes_available, depth, prior = nil)
  if(dataset.size < Idhja22.config.min_dataset_size)
    return Idhja22::LeafNode.build(dataset, prior)
  end

  #if successful termination - create and return a leaf node
  if(dataset.terminating? && depth > 0) # don't terminate without splitting the data at least once
    return Idhja22::LeafNode.build(dataset, prior)
  end

  if(depth >= 3) # don't let trees get too long
    return Idhja22::LeafNode.build(dataset, prior)
  end

  #if we have no more attributes left to split the dataset on, then return a leafnode
  if(attributes_available.empty?)
    return Idhja22::LeafNode.build(dataset, prior)
  end

  node = DecisionNode.build(dataset, attributes_available, depth, prior)

  return node
end

Instance Method Details

#==(other) ⇒ Object



49
50
51
# File 'lib/idhja22/tree/node.rb', line 49

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