Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/SelfModifiedDecisionTree.rb

Overview

input can be quite dangerous. #

Instance Method Summary collapse

Instance Method Details

#classificationObject



91
# File 'lib/SelfModifiedDecisionTree.rb', line 91

def classification; collect { |v| v.last }; end

#entropyObject

calculate information entropy



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/SelfModifiedDecisionTree.rb', line 94

def entropy
  return 0 if empty?

  info = {}
  total = 0
  each {|i| info[i] = !info[i] ? 1 : (info[i] + 1); total += 1}

  result = 0
  info.each do |symbol, count|
    result += -count.to_f/total*Math.log(count.to_f/total)/Math.log(2.0) if (count > 0)
  end
  result
end