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