C2W3 assignment: I can't pass the second test case. What did I do wrong here?

Here is my codes:

codes removed as posting codes from grade function codes is violation of Code of conduct and considered against community guidelines. if a mentor wants to look at your codes they will ask you to DM your codes.

Output:
Test Case 1

   Time  Event
0     5      0
1    10      1
2    15      0 

       0   1   2
Time   5  10  15
Event  0   1   0
t: 5 frac: 1 -  [False, False, False] 0 / [True, True, True] 3 = 1.0 S: 1.0
..........
t: 10 frac: 1 -  [False, True, False] 1 / [True, False, True] 2 = 0.5 S: 0.5
..........
t: 15 frac: 1 -  [False, False, False] 0 / [True, False, True] 2 = 1.0 S: 0.5
..........
Test Case 1 Event times: [0, 5, 10, 15], Survival Probabilities: [1.0, 1.0, 0.5, 0.5]

Test Case 2

   Time  Event
0     2      0
1    15      0
2    12      1
3    10      1
4    20      1 

       0   3   2   1   4
Time   2  10  12  15  20
Event  0   1   1   0   1
t: 2 frac: 1 -  [False, False, False, False, False] 0 / [True, True, True, True, True] 5 = 1.0 S: 1.0
..........
t: 10 frac: 1 -  [False, False, False, True, False] 1 / [True, True, True, False, True] 4 = 0.75 S: 0.75
..........
t: 12 frac: 1 -  [False, False, True, False, False] 1 / [True, True, False, False, True] 3 = 0.6666666666666667 S: 0.5
..........
t: 15 frac: 1 -  [False, False, False, False, False] 0 / [True, True, False, False, True] 3 = 1.0 S: 0.5
..........
t: 20 frac: 1 -  [False, False, False, False, True] 1 / [True, True, False, False, False] 2 = 0.5 S: 0.25
..........
Test Case 2 Event times: [0, 2, 10, 12, 15, 20], Survival Probabilities: [1.0, 1.0, 0.75, 0.5, 0.5, 0.25] 
...
Error: Wrong output for Test Case 2. for variable in position 5.
 2  Tests passed
 1  Tests failed

So I pass Test case 1 but not test case 2 variable 5, I tried doing the calculation by hand but my work seems correct. could anyone help me?

1 Like

Make sure you are only replace the None placed between ###START AND END CODE HERE###

I can surely see too many editing and hard-coding the path to recall a code statment. Your issue might also not be related to only this grade function as passing unittest doesn’t always confirm that codes are correct.

2 Likes

even after cleaning up my debugs, it still does raise the exception for test case 2 variable 5 where my function would return a 0.25 while the expected answer is 0. Any other clues on what is happening? if not I will not pass week 3 and not get the certs

my numerator boolean counts is where T=t or Event = 1.
my denorminator boolean counts is where T>t and Event = 0.
updated p by multiplying p with the (1-fraction)

I don’t get where the survival model returning 0, there is person dead at T = 20 and total know censored or alive to be 2. So the faction will be 0.5 and survival model = 0.5 * S(15) = 0.5 * 0.5 = 0.25.

I didn’t include anymore codes to prevent myself from violating the rules of the forums.


Test Case 2

   Time  Event
0     2      0
1    15      0
2    12      1
3    10      1
4    20      1 

Test Case 2 Event times: [0, 2, 10, 12, 15, 20], Survival Probabilities: [1.0, 1.0, 0.75, 0.5, 0.5, 0.25] 

Error: Wrong output for Test Case 2. for variable in position 5.
 2  Tests passed
 1  Tests failed

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-31-2b623eeafe78> in <module>
      1 ### do not edit this code cell
----> 2 HomemadeKM_test(HomemadeKM)

~/work/W3A1/public_tests.py in HomemadeKM_test(target)
    151     ]
    152 
--> 153     multiple_test(test_cases, target)
    154 
    155 

~/work/W3A1/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 HomemadeKM. Check your equations and avoid using global variables inside the function.

Expected Output:

Test Case 1 Event times: [0, 5, 10, 15], Survival Probabilities: [1.0, 1.0, 0.5, 0.5]
Test Case 2 Event times: [0, 2, 10, 12, 15, 20], Survival Probabilities: [1.0, 1.0, 0.75, 0.5, 0.5, 0.0] 

 All tests passed.
1 Like

please click on name and then message me screenshots of your grade function codes

1 Like