AI for Medicine: AI for Prognosis: Week 2 Assignment

Greetings,

I completed the assignment for week 2.

The unit test for exercise 2 indicates there is an error, but I can’t figure it out to debug. All the outputs are correct, but there is something at the end that says wrong shape. Here is the output below:

Computed fraction missing: 0.75
Fraction of rows missing from X_train: 0.6986594132504371
Fraction of rows missing from X_val: 0.703962703962704
Fraction of rows missing from X_test: 0.0
Error: Wrong shape.

I also received this message in the grader.

Cell #9. Can’t compile the student’s code. Error: AssertionError(‘Not all tests were passed for fraction_rows_missing. Check your equations and avoid using global variables inside the function.’,)

As I mentioned earlier, the outputs are correct, but it’s telling me it’s the wrong shape.

the grader also list a score of 0/6, but I passed all the exercises.

I deleted the notebook and started with a fresh notebook to insure that the cells were not altered beyond the # for code entires, but the error persists and I cannot move forward.

Any help would be appreciated.

1 Like

I do not have access to that course, but one thing to check is whether there are more test cases that you cannot see. In a lot of the other courses (MLS, DLS, M4ML, NLP …) there are tests you can see in the notebooks and then additional cases that are imported from utility files and just called from the notebook. It could be that the “wrong shape” error is coming from another test that you have not examined yet. E.g. you hard-coded some assumptions about the dimensions of the input objects and the other test uses different dimensions.

You can find the name of the utility files by reading the “import” block early in the notebook. Then click “File → Open” and open the file containing the tests.

I think it has to do with using global variables as stated in the error message.
I’ll suggest you review your definition of the fraction_rows_missing function. Use the hints. While getting the number of rows, make sure you do not hard code it (remember, a dataframe’s number of rows can be gotten by indexing the shape attribute) .

As a reminder, these are the hints provided in the assignment:

Hints

  • The pandas.DataFrame.isnull() method is helpful in this case.
  • Use the pandas.DataFrame.any() method and set the axis parameter.
  • Divide the total number of rows with missing data by the total number of rows. Remember that in Python, True values are equal to 1.

The problem was with the output. I wrapped the return statement with the float() class and it worked. I’m not sure why, but I am just going to move on to the next course.

Thanks for jumping in and offering some help. cheers

2 Likes