mirror of
https://github.com/dkam/decisiontree.git
synced 2025-12-27 22:54:52 +00:00
Fix sum error
This commit is contained in:
@@ -127,12 +127,12 @@ module DecisionTree
|
||||
index = attributes.index(attribute)
|
||||
|
||||
values = data.map { |row| row[index] }.uniq
|
||||
remainder = values.sort.inject(0, :+) do |val|
|
||||
remainder = values.sort.inject(0) do |sum, val|
|
||||
classification = data.each_with_object([]) do |row, result|
|
||||
result << row.last if row[index] == val
|
||||
end
|
||||
|
||||
((classification.size.to_f / data.size) * classification.entropy)
|
||||
sum + ((classification.size.to_f / data.size) * classification.entropy)
|
||||
end
|
||||
|
||||
[data.classification.entropy - remainder, index]
|
||||
|
||||
Reference in New Issue
Block a user