# Unit test case failure in C2\_W4\_Decision\_Tree\_with\_Markdown

**URL:** <https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658>\
**Category:** Advanced Learning Algorithms\
**Tags:** week-module-4\
**Created:** [September 28, 2024, 10:00am UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658 "2024-09-28T10:00:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishalghadge](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/vishalghadge/32/25294_2.png) [@vishalghadge](https://community.deeplearning.ai/u/vishalghadge)\
**Post date:** [September 28, 2024, 10:00am UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/1 "2024-09-28T10:00:03Z")

</div>

Hi,  
During execution of

```auto
# UNIT TESTS    
split_dataset_test(split_dataset)

```

Error is

```auto
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-11-197878478053> in <module>
     31 
     32 # UNIT TESTS
---> 33 split_dataset_test(split_dataset)

~/work/public_tests.py in split_dataset_test(target)
     79 'right': np.array([2, 7, 9, 10])}
     80 
---> 81 assert np.allclose(right, expected['right']) and np.allclose(left, expected['left']), f"Wrong value when target is at index 0. \nExpected: {expected} \ngot: \{left:{left}, 'right': {right}\}"
     82 
     83

```

I found that one of the unit test is wrongly written, because of this its failing.

Test case form `public_tests.py`

```auto
# Case 3

X = (np.random.rand(11, 3) > 0.5) * 1 # Just random binary numbers
X_t = np.array([[0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0]])
X = np.concatenate((X, X_t.T), axis=1)

left, right = target(X, [1, 2, 3, 6, 7, 9, 10], 3)
expected = {'left': np.array([1, 3, 6]),

'right': np.array([2, 7, 9, 10])}

assert np.allclose(right, expected['right']) and np.allclose(left, expected['left']), f"Wrong value when target is at index 0. \nExpected: {expected} \ngot: \{left:{left}, 'right': {right}\}"

print("\033[92m All tests passed.")

```

From above code you can see that right and left arrry values are not correct

From code

`X_t = np.array([[0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0]])`

you can see indices for value `1` are `1,3,5,6` and for `0` are `0,2,4,7,8,9,10`

which are not matching with left and right arrays used for verification.

In code

```auto
expected = {'left': np.array([1, 3, 6]),
'right': np.array([2, 7, 9, 10])}

```

Can someone please fix this test case? or let me know if my understanding is not correct here.

Thanks

---

<div class="post-metadata">

**Author:** ![nadtriana](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nadtriana/32/167698_2.png) [@nadtriana](https://community.deeplearning.ai/u/nadtriana)\
**Post date:** [September 28, 2024, 1:33pm UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/2 "2024-09-28T13:33:55Z")

</div>

Your understanding of the issue seems to be correct. The expected output values in the test case do not match the actual logic of splitting the dataset based on the 0s and 1s in the target column.

@chris.favila, could you please look into this?

---

<div class="post-metadata">

**Author:** ![vishalghadge](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/vishalghadge/32/25294_2.png) [@vishalghadge](https://community.deeplearning.ai/u/vishalghadge)\
**Post date:** [October 1, 2024, 6:08am UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/3 "2024-10-01T06:08:06Z")

</div>

@chris.favila @nadtriana  
Hello,  
Do you have any ETA for this fix?

---

<div class="post-metadata">

**Author:** ![chris.favila](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/chris.favila/32/126338_2.png) [@chris.favila](https://community.deeplearning.ai/u/chris.favila)\
**Post date:** [October 1, 2024, 9:47am UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/4 "2024-10-01T09:47:32Z")

</div>

Hi Vishal and Nayid. Sorry for the late reply. We will look into it this week.

---

<div class="post-metadata">

**Author:** ![chris.favila](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/chris.favila/32/126338_2.png) [@chris.favila](https://community.deeplearning.ai/u/chris.favila)\
**Post date:** [October 4, 2024, 4:37am UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/5 "2024-10-04T04:37:13Z")

</div>

Hi Vishal. Can you send me your notebook (ipynb) file via DM? Thanks.

---

<div class="post-metadata">

**Author:** ![vishalghadge](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/vishalghadge/32/25294_2.png) [@vishalghadge](https://community.deeplearning.ai/u/vishalghadge)\
**Post date:** [October 4, 2024, 12:00pm UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/6 "2024-10-04T12:00:29Z")

</div>

Sent you DM with file attached.

---

<div class="post-metadata">

**Author:** ![chris.favila](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/chris.favila/32/126338_2.png) [@chris.favila](https://community.deeplearning.ai/u/chris.favila)\
**Post date:** [October 7, 2024, 12:26am UTC](https://community.deeplearning.ai/t/unit-test-case-failure-in-c2-w4-decision-tree-with-markdown/699658/7 "2024-10-07T00:26:28Z")

</div>

Hi Vishal. I saw your solution and saw that you’re not using the `node_indices` parameter in your code. Remember that the `split_dataset()` function uses this to indicate which subset of the samples needs to be analyzed. Check the function inputs and expected output for **Case 2** in the in-notebook unit test:

 ![mls_c2w4_splitdataset](https://global.discourse-cdn.com/dlai/original/3X/5/4/5449db75abd7bc27bfd48c20c66be4e04b0b7e9b.png)

This should guide you in revising your solution. Hope this helps!
