Class: Array
Instance Method Summary collapse
- #classification ⇒ Object
-
#entropy ⇒ Object
calculate information entropy.
Instance Method Details
#classification ⇒ Object
17 |
# File 'lib/decisiontree/id3_tree.rb', line 17 def classification; collect { |v| v.last }; end |
#entropy ⇒ Object
calculate information entropy
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/decisiontree/id3_tree.rb', line 20 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 |