Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite recursion due to the handling of zero gains in id3_continuous #19

Open
nicomahler opened this issue May 7, 2014 · 0 comments

Comments

@nicomahler
Copy link

On a real production dataset with 5 explanatory variables and ~1000 lines, I received a SystemStackError: stack level too deep when calling DecisionTree::ID3Tree#train.

Trying to figure out what was happening, I built the following simple dataset, which allows to reveal the bug:

attributes = ["X0", "X1", "X2", "X3"]
data = [["a", 0, 1, 1, 1], ["a", 0, 1, 0, 0], ["a", 0, 0, 1, 0], ["a", 0, 0, 0, 1]]
data_type = {X0: :discrete, X1: :continuous, X2: :continuous, X3: :continuous}
tree = DecisionTree::ID3Tree.new(attributes, data, 1, data_type)
tree.train  # SystemStackError is raised here!

The reason of this bug seems to lie in the specific output ([-1, -1]) of DecisionTree::ID3Tree#id3_continuous in the case if values.size == 1 (see this line).

Returning [0, -1] instead of [-1, -1] in the cases if values.size == 1 and if gain.size == 1 in the method #id3_continuous solves the problem.

It would also be relevant to stop the recursion in the case where the selection of each variable leads to a zero gain. That can be done adding in #id3_train the following line:

return data.first.last if performance.all? { |a, b| a <= 0 }

after this line:

performance = attributes.collect { |attribute| fitness_for(attribute).call(data, attributes, attribute) }

What do you think?

Do you want me to make a pull request with these changes?

sclinede added a commit to sclinede/decisiontree that referenced this issue Aug 30, 2016
sclinede added a commit to sclinede/decisiontree that referenced this issue Aug 30, 2016
sclinede added a commit to sclinede/decisiontree that referenced this issue Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant