Week4_Programming Assignment - nan error. Getting 0 marks

Question 3 - Compute Information Gain
Expected Result and my result is same but there is error of nan when unit tests are run. When I submit the assignment, I should at least get the marks for correct answers for Questions 1, 2 and 4. But I’m getting 0.
I don’t know how to solve the ‘nan’ issue. But it’s ok as long as I get marks for my correct answers for other questions

nan error - when running unit test
AssertionError Traceback (most recent call last)
in
9
10 # UNIT TESTS
—> 11 compute_information_gain_test(compute_information_gain)

~/work/public_tests.py in compute_information_gain_test(target)
113
114 result = target(X, y, node_indexes, 1)
→ 115 assert np.isclose(result, 0, atol=1e-6), f"Wrong information gain. Expected {0.0} got: {result}"
116
117 print(“\033[92m All tests passed.”)

AssertionError: Wrong information gain. Expected 0.0 got: nan

nan error - when submitting assignment
ell #11. Can’t compile the student’s code. Error: AssertionError(‘Wrong information gain. Expected 0.0 got: nan’)
Traceback (most recent call last):
File “/home/www/app/grading/exceptions.py”, line 112, in handle_solution_errors
yield {}
File “/home/www/app/grading/abstract.py”, line 393, in _grade
context = compiled_code.run(cell_index=cell.index)
File “/home/www/app/grading/submission/compiled_code.py”, line 195, in run
return list(self._code_items.values())[cell_num - 1].run()
File “/home/www/app/grading/submission/compiled_code.py”, line 54, in run
return import_module(self.import_statement, items)
File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 677, in _load_unlocked

I’ve seen another post where another Student faced the same issue, but he managed to solve the nan issue.

Can I not submit the assignment without solving the “nan” issue and still get marks for the 3 remaining questions. Why do I get 0 marks. Why 1 unit test fail for 1 question is penalising the whole assignment by not letting it to be submitted

Hello @churamani_prasad,

The tests do not guarantee problem-free. We can pass the public tests but fail some private tests at submission. Our job is to present working code, and that should be our focus :wink:

We can suggest you how to narrow down the problem, as for how to correct it, it is going to be your challenge. The code snippet below is from the hint that is also available in your notebook under the code cell of exercise 3:

def compute_information_gain(X, y, node_indices, feature):

    <some provided code skipped>

    ### START CODE HERE ###


    print('================Begin====================') # ADDED for inspection. Should be removed afterwards to avoid submission failure.
    print('X', X) # ADDED for inspection. Should be removed afterwards to avoid submission failure.
    print('y', y) # ADDED for inspection. Should be removed afterwards to avoid submission failure.
    print('node_indices', node_indices) # ADDED for inspection. Should be removed afterwards to avoid submission failure.
    print('feature', feature) # ADDED for inspection. Should be removed afterwards to avoid submission failure.


    # Your code here to compute the entropy at the node using compute_entropy()
    node_entropy = 

    print('node_entropy ', node_entropy) # ADDED for inspection. Should be removed afterwards to avoid submission failure.

    # Your code here to compute the entropy at the left branch
    left_entropy = 
    # Your code here to compute the entropy at the right branch
    right_entropy = 

    # Your code here to compute the proportion of examples at the left branch
    w_left = 

    # Your code here to compute the proportion of examples at the right branch
    w_right = 

    # Your code here to compute weighted entropy from the split using 
    # w_left, w_right, left_entropy and right_entropy
    weighted_entropy = 

    # Your code here to compute the information gain as the entropy at the node
    # minus the weighted entropy
    information_gain = 
    ### END CODE HERE ###  

    return information_gain

You see that, there are many variables for storing intermediate results that are used to finally compute the gain that is returned by the function. Now, you said your function returned a np.nan. To find out where the problem is, the best would be to print the intermediate variables out so that we can see which one starts to have problem.

For us to track, we can add some prints to show the inputs to the function, and then one print per each of those intermediate variable. I added the print for node_entropy as an example.

Good luck debugging!

Cheers,
Raymond

Thanks for the reply. I managed to debug and find the reason.

Since, you are a mentor, I’m putting my feedback below. If it’s useful, please help to see if something can be done about it

But my other question still remains. Should the failure of just 1 test case for 1 question be the criteria to award 0 marks. Should the learner not get marks for the other questions he did correctly. Due to this, it gets impossible to pass the course. It happened to me for one of the assignments for the previous course as well. One unit test was not passing. I thought, no problem, instead of getting 100% marks, I can still get, may be 80% or something as rest of the questions are correct. But when I submitted, I got awarded 0 marks. Anyway, later I worked and resolved it. But that’s not the point. The point is that Student should be able to get marks awarded for at least the right questions so he can pass the course

The assignment should not force you to do all questions correct or get awarded 0 marks. That does not look correct

Hello @churamani_prasad,

It doesn’t always happen like that - I experienced cases that I got somewhere between 0% and 100%, but sometimes cases like yours. I don’t know what’s going on behind the scene and I have no direct influence on changing how the system works. However, I can pass your message on to a course staff for their consideration of any follow-up, but I can’t guarantee any time frame and it is possible that no difference will be made before you finish the MLS.

Before I pass it on, would you mind to go to that assignment page, take a screenshot of the autograder giving you 0 marks, then click on one of those reports, and copy and paste the grader’s message here? I expect the message would say some exercises were correct and there was a problem with one of the other exercises.

Pick one such report, take a screenshot, and copy the corresponding text message here should be enough for now.

Cheers,
Raymond

Hello @rmwkwok

Understood and agree with all your points. In case this is helpful for others or if it makes the experience slight better, here is the screenshots and error details for Course Staff to have a further look

Grader Error output
Cell #11. Can’t compile the student’s code. Error: AssertionError(‘Wrong information gain. Expected 0.0 got: nan’)
Traceback (most recent call last):
File “/home/www/app/grading/exceptions.py”, line 112, in handle_solution_errors
yield {}
File “/home/www/app/grading/abstract.py”, line 393, in _grade
context = compiled_code.run(cell_index=cell.index)
File “/home/www/app/grading/submission/compiled_code.py”, line 195, in run
return list(self._code_items.values())[cell_num - 1].run()
File “/home/www/app/grading/submission/compiled_code.py”, line 54, in run
return import_module(self.import_statement, items)
File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1006, in _gcd_import
File “”, line 983, in _find_and_load
File “”, line 967, in _find_and_load_unlocked
File “”, line 677, in _load_unlocked
File “”, line 728, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/tmp/student_solution_cells/cell_11.py”, line 23, in
compute_information_gain_test(compute_information_gain)
File “/tmp/public_tests.py”, line 106, in compute_information_gain_test
assert np.isclose(result, 0, atol=1e-6), f"Wrong information gain. Expected {0.0} got: {result}"
AssertionError: Wrong information gain. Expected 0.0 got: nan