igrigorik/decisiontree — pull request #8 by rustyio (2013-01-15 19:55:30+00:00)
Title: Fix infinite recursion.

```ruby
require 'decisiontree'

labels = [:a, :b, :c]
data = [
["a1", "b0", "c0", "RED"],
["a1", "b1", "c1", "RED"],
["a1", "b1", "c0", "BLUE"],
["a1", "b0", "c1", "BLUE"]
]

tree = DecisionTree::ID3Tree.new(labels, data, "RED", :discrete)
tree.train
```

The preceding sample causes infinite recursion.

When all attributes result in the same fitness score, the code continuously chooses to partition on the first attribute. As you can see in the example above, this does nothing to partition the data.

While it may not be the provably *best* approach, this pull request solves the problem by checking if all attributes result in the same fitness score, and if so, choosing a best attribute randomly.