Doubt in implementation of decision tree

I am not able to understand the base case or the case of hitting the leaf node in the recursion of train() function.

According to implementation when we are at leaf node, the feature which has highest info gain will divide the data into two parts (i.e, left and right). Out of which one part will be empty. How can we be sure that always one part is empty? Or when we reach a state where out of 2 data partition, (on the basis of highest info gain feature) one is empty, how we can be sure that this is leaf node??

According to me we should reach a leaf node when the data left with us has all labels as same or there is only one type of y_label. Is this correct? Can we implement train() using this as the base case also??

hey @Nimish-Malhotra-2431984440178391,
We are checking to get a case where we are left with on only one label in the data and that too we have it in one side or the tree , either left or right.
This is the case of leaf node.

Yes you are correct and this can be done too.
But , how will you check that all labels are from one class ? By checking uniqueness of that column , correct.
Similarly , we are doing it here too. We are not just checking the uniqueness, in fact if all the labels are from yes class then , all values will be greater than previous mean , i.e 0.5 , means all labels are same.

Both implementations means the same , just the thing is , your approach is different.

I hope this helped you understand it more properly.
Thank You and Happy Learning :slightly_smiling_face:.