'ID3 algorithm: RecursionError: maximum recursion depth exceeded in comparison
I have this function to build ID3 decision tree:
def buildTree(df,tree=None):
Class = df.keys()[-1] #To make the code generic, changing target variable class name
#Here we build our decision tree
#Get attribute with maximum information gain
node = find_winner(df)
#Get distinct value of that attribute e.g Salary is node and Low,Med and High are values
attValue = np.unique(df[node])
#Create an empty dictionary to create tree
if tree is None:
tree={}
tree[node] = {}
#We make loop to construct a tree by calling this function recursively.
#In this we check if the subset is pure and stops if it is pure.
for value in attValue:
subtable = get_subtable(df,node,value)
clValue,counts = np.unique(subtable['For the management of this project'],return_counts=True)
if len(counts)==1:#Checking purity of subset
tree[node][value] = clValue[0]
else:
tree[node][value] = buildTree(subtable) #Calling the function recursively
return tree
I got this error:
RecursionError: maximum recursion depth exceeded in comparison
I tried to fix it using sys.setrecursionlimit()
, but I still have the same error. I thought I should minimize the depth of my decision tree.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|