[URGENT] Unable to progress in Week 4 due to assertion error in Exercise 2 of Practice Lab: Decision Trees

Hi all,

The Exercise 2 in lab for decision tress seems like to have an incorrect assertion check which is not letting me pass the unit tests.

Specifically the below assertion seems incorrect, can someone please take a look and fix the lab,

~/work/public_tests.py in split_dataset_test(target)
44 assert type(right[0]) == int, f"Wrong type for elements in the right list. Expected: number got: {type(right[0])}"
45
—> 46 assert len(left) == 2, f"left must have 2 elements but got: {len(left)}"
47 assert len(right) == 3, f"right must have 3 elements but got: {len(right)}"

Link to lab: Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera

I would appreciate a quick reply as I am not able to complete the course and I have deadline approaching in couple of days. I will fail the course otherwise, please help!!!

@Akshay_Kumar87 You can click on hints (in the assignment lab itself) for more details that could help you understand the assignment and the code.

1 Like

This lab has not changed since August 2022.
No other student has reported an issue with that assert.
My code does not throw that assert.
So I suspect that the issue is in your code.

Hi everyone,

thanks for your help. I checked the hints, my code is exactly the same as in hints. The assertion error only occurs for 2nd unit test which I copied below. The question asks us to split based on color of mushroom cap - whether it is brown or not. The correct answer is
left_indices = [0 ,2,4]
right_indices = [6,8]

I verified it by simply looking at data set as well.

I get assertion error
AssertionError: left must have 2 elements but got: 3

But clearly left has 3 elements so why should it have 2?

I am not sure why no one else reported the issue. I have cleared the cookies/cache it still throws the assert. I have no idea how I can progress. If I don’t get help I won’t be able to pass

======================

Case 2

root_indices_subset = [0, 2, 4, 6, 8]
left_indices, right_indices = split_dataset(X_train, root_indices_subset, feature)

print(“CASE 2:”)
print("Left indices: ", left_indices)
print("Right indices: ", right_indices)

This implies that the problem is in your code, and not in the assignment.

Tip for those who find this thread later:

  • Don’t use global variables inside a function.