mirror of
https://github.com/dkam/decisiontree.git
synced 2025-12-28 15:14:52 +00:00
Update array.rb
This commit is contained in:
@@ -2,7 +2,7 @@ class Array
|
|||||||
def entropy
|
def entropy
|
||||||
each_with_object(Hash.new(0)) do |i, result|
|
each_with_object(Hash.new(0)) do |i, result|
|
||||||
result[i] += 1
|
result[i] += 1
|
||||||
end.values.sum do |count|
|
end.values.inject(0, :+) do |count|
|
||||||
percentage = count.to_f / length
|
percentage = count.to_f / length
|
||||||
|
|
||||||
-percentage * Math.log2(percentage)
|
-percentage * Math.log2(percentage)
|
||||||
|
|||||||
Reference in New Issue
Block a user