AI For Medical prognosis W2

failing the C2_W2_Assignment grader.

i have used
def fraction_rows_missing(df):
‘’’
Return percent of rows with any missing
data in the dataframe.

Input:
    df (dataframe): a pandas dataframe with potentially missing data
Output:
    frac_missing (float): fraction of rows with missing data
'''
### START CODE HERE (REPLACE 'None' with your code) ###

### END CODE HERE ###

and i am getting :
Example dataframe:

  a    b

0 NaN 1.0
1 1.0 NaN
2 1.0 0.0
3 NaN 1.0

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.
2 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in
1 ### test cell ex1 - do not modify this test cell
----> 2 fraction_rows_missing_test(fraction_rows_missing, X_train, X_val, X_test)

~/work/W2A1/public_tests.py in fraction_rows_missing_test(target, X_train, X_val, X_test)
40 ]
41
—> 42 multiple_test(test_cases, target)

~/work/W2A1/test_utils.py in multiple_test(test_cases, target)
121 print(‘\033[92m’, success," Tests passed")
122 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
→ 123 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for fraction_rows_missing. Check your equations and avoid using global variables inside the function.

xpected Output:

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
 All tests passed.

i think that this is causing me to fail this task which is strange. can you please help.

Regards

Zvi

1 Like

Hi @Zvi_Boiangou,

I suggest you check exercise “C2_W2_Lab_2_missing_data_and_applying_a_mask” and go carefully over how the different functions work and how you solved that exercise. If you still face issues, let me know.

Please remove the part of code that you used to solve the question.
Thank you.

1 Like

Hello @Zvi_Boiangou,

the way you applied the code by recalling data frame again to already assignment function call is creating the error.

other error do not use numpy to this code.

recall the missing data as numerator and length of df as denominator, and then recall the return statement as a divide between the two. you will get the expected output.

Regards
DP