C3_W1 practice lab2 q2:select_threshold

I am getting an error , i have checked it many times but it’s not resolving

Best epsilon found using cross-validation: 8.981862e-02

Best F1 on Cross Validation Set: 0.985025

AssertionError Traceback (most recent call last)
----> 8 select_threshold_test(select_threshold)

~/work/public_tests.py in select_threshold_test(target)
8 best_epsilon, best_F1 = target(y_val, p_val)
----> 9 assert np.isclose(best_epsilon, 0.04, atol=0.3 / 1000), f"Wrong best_epsilon. Expected: {0.04} got: {best_epsilon}"
10 assert best_F1 == 1, f"Wrong best_F1. Expected: 1 got: {best_F1}"

AssertionError: Wrong best_epsilon. Expected: 0.04 got: 0.28014


The hints provided a step by step guide on how to code the different calculations. Have you checked your code against the guide? Don’t forget to use parenthesis to enforce evaluation order. For example, operators like * and / have higher precedence over + and -. If you are still having problem after checking, then, send me a direct message with the function, and I will have a look for you.


The problem is with the calculation for true positives and false positives. You have got the formula the wrong way round.

The condition for true positives:
predictions =1 and ground truth =1

The condition for false positives :
prediction =1 and ground truth=o

1 Like