require 'set' module Ai4r module Classifiers NUMERIC_CLASS_TYPE = 1 NOMINAL_CLASS_TYPE = 2 module ClassifierHelper def default_data_labels(data_examples) data_labels = [] data_examples[0][0..-2].each_index do |i| data_labels[i] = "attribute_#{i+1}" end data_labels[data_labels.length]="class_value" return data_labels end def check_data_examples(data_examples) if !data_examples || data_examples.empty? raise ArgumentError,"Examples data set must not be empty." elsif !data_examples.first.is_a?(Array) raise ArgumentError,"Unkown format for example data." end end # Returns attributes number, including class attribute def num_attributes(data_examples) return 0 if !data_examples || data_examples.empty? || !data_examples.first.is_a?(Array) return data_examples.first.size end # Returns an array with the domain of each attribute (Set instance # containing all possible values) # Return example: # => [#, # #80"}>, # #, # #] def build_domains(data_examples) domains = Array.new(num_attributes(data_examples)) { Set.new } data_examples.each do |data| data.each_index {|attr_index| domains[attr_index] << data[attr_index]} end return domains end end end end