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