Result1 and Result2 are being executed with the same parameters of (X, y, node_indexes, 0). Is this a bug is this bit of code? Is this why I am getting AssertionErrors?
Please advise why I am getting these AssertionErrors when running the Unit Tests but my results are the same as the expected outcomes for the Exercise 3 and 4.
First, those expected outcomes only mean your code works for those specific cases, and don’t guarantee for any other cases, so we have more tests including the one mentioned by you - that detected that your code doesn’t return a zero gain when the target is pure (all 0s in your case).
Just think about the principle: if the incoming data is already well grouped, because they are all of the same class, then there should be no need to further split them up. We want to split the data because they have mixed classes, and we hope that after splitting, the child nodes each contain only one class of samples. The maths should be consistent with this rationale too. If the incoming data is already of just one class, then no way can we further split it to achieve any gain, or in other words, the gain should just be zero. Since your code doesn’t return a zero, you get this error.
As for your last question, you may question whether it is necessary to repeat the test two times, but repeating it for two times itself shouldn’t be a problem because, in both times, your code should return a zero gain. Therefore, I think it is not relevant to the error you are seeing. As for why they repeat the test, perhaps this can help catch some error that we cannot think of right here right now.
Since you have looked at the test, the data is very simple. It is so simple that we can literally work out the math on our own on a piece of paper. This is why I suggest you to add a couple of print lines to show the values of all intermediate variable ever used in your code for Exercise 3, and verify them yourself. The value should be consistent with the provided math equations, and the rationale I shared above - that there shouldn’t be any information gain. I hope that in this way you will be able to find the bug yourself - finding bug is a part of the assignment.
As for exercise 4, it seems they are related to each other. Let’s see if it will go away after exercise 3 is fixed.