Skip to content

Commit

Permalink
Fix infinite recursion (solution by @nicomahler)
Browse files Browse the repository at this point in the history
  • Loading branch information
sclinede committed Aug 30, 2016
1 parent 7b034dc commit b310a7f
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/decisiontree/id3_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def id3_train(data, attributes, default, _used={})
# 2. Pick best attribute
# 3. If attributes all score the same, then pick a random one to avoid infinite recursion.
performance = attributes.collect { |attribute| fitness_for(attribute).call(data, attributes, attribute) }
return data.first.last if performance.all? { |a, b| a.to_f <= 0 }
max = performance.max { |a,b| a[0] <=> b[0] }
min = performance.min { |a,b| a[0] <=> b[0] }
max = performance.sample if max[0] == min[0]
Expand Down

0 comments on commit b310a7f

Please sign in to comment.