Class: Ai4r::Classifiers::EvaluationNode

Inherits:
Object
  • Object
show all
Defined in:
lib/ai4r/classifiers/id3.rb

Overview

:nodoc: all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_labels, index, values, nodes) ⇒ EvaluationNode

Returns a new instance of EvaluationNode.



274
275
276
277
278
279
# File 'lib/ai4r/classifiers/id3.rb', line 274

def initialize(data_labels, index, values, nodes)
  @index = index
  @values = values
  @nodes = nodes
  @data_labels = data_labels
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



272
273
274
# File 'lib/ai4r/classifiers/id3.rb', line 272

def index
  @index
end

#nodesObject (readonly)

Returns the value of attribute nodes.



272
273
274
# File 'lib/ai4r/classifiers/id3.rb', line 272

def nodes
  @nodes
end

#valuesObject (readonly)

Returns the value of attribute values.



272
273
274
# File 'lib/ai4r/classifiers/id3.rb', line 272

def values
  @values
end

Instance Method Details

#get_rulesObject



287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/ai4r/classifiers/id3.rb', line 287

def get_rules
  rule_set = []
  @nodes.each_index do |child_node_index|
    my_rule = "#{@data_labels[@index]}=='#{@values[child_node_index]}'"
    child_node = @nodes[child_node_index]
    child_node_rules = child_node.get_rules
    child_node_rules.each do |child_rule|
      child_rule.unshift(my_rule)
    end
    rule_set += child_node_rules
  end
  return rule_set
end

#value(data) ⇒ Object



281
282
283
284
285
# File 'lib/ai4r/classifiers/id3.rb', line 281

def value(data)
  value = data[@index]
  return ErrorNode.new.value(data) if !@values.include?(value)
  return nodes[@values.index(value)].value(data)
end