Prog. assign.: Anomaly Detection - test for 2nd exercise is not accurate!

It looks like the test code checks only the best F1 score. The best epsilon is different from the Expected. See it in the attached screenshot.

Hello @Robert_Ascan,

These are 2 tests. The pairs of values you compare with belong to one test, and the green “All tests passed” message comes from another set of tests.

I can get the expected output.

Here is the bugged code that passed the Tester but failed to produce the best epsilon. step_size/1000 is added to avoid epsilon taking the value of zero or so close to zero where all examples are True Negatives (tp, fp, fn are zeros). Without it the Tester returns “Division by zero”. When I run the codes following this exercise (that rely on my code in this exercise) they don’t produce the expected result.

Actually, this code (with step_size/1000) produces the expected results for both the “best epsilon” and the “best F1 score” but still fails its task when running the other codes in this assignment that rely on my code in this function. The screenshot above (where the best epsilon is different from the expected result) is produced when the threshold is set to (epsilon + step_size). I have no clue where the bug might be.

Hello @Robert_Ascan,

Your code is fine except for 2 points:

  1. You have a good reason to handle the Division by zero error, but modifying epsilon is not the most appropriate way, so I would remove the step_size/1000 thing, and don’t you think the choice of this addition is quite aribitary?

  2. To handle the division by zero, we can use an if statement that controls the one case when either or both the denominator of precision or/and recall is/are zero, and in that case, the calculated F1 score can be set to zero and I will leave the justification to you think about it. Having the if statement will bypass the division and thus mitigate the error.


PS: I am removing your code since we can’t share it here.

1 Like

Thanks, Raymond for the hint! The “if-statement” de-bugged my code. :+1:

You are welcome Robert :wink: