C3_w1_anomaly detection

Tried my version of the code to solve Exercise 2 (setting the threshold epsilon to get max F1 score)…after multiple attempts i ended up using the code given in the hints section to no avail!!

please help!


GRADED FUNCTION: select_threshold

def select_threshold(y_val, p_val): 
    Finds the best threshold to use for selecting outliers 
    based on the results from a validation set (p_val) 
    and the ground truth (y_val)
        y_val (ndarray): Ground truth on validation set
        p_val (ndarray): Results on validation set
        epsilon (float): Threshold chosen 
        F1 (float):      F1 score by choosing epsilon as threshold

    best_epsilon = 0
    best_F1 = 0
    F1 = 0
    step_size = (max(p_val) - min(p_val)) / 1000
    for epsilon in np.arange(min(p_val),max(p_val),step_size):
   # moderator edit: code removed

    return best_epsilon, best_F1

Hi @Raghavendran_n ,

The ‘if’ statement is outside of the ‘for’ loop, so ‘if’ block of code only get executed once.

Thank you, KIc !! spent hours figuring this out and it turns out to be bad indentation!

thanks, again!

Please do not post your code on the forum. That’s not allowed by the community standard.

The mentors are not here to fix your code - we’re here to give you hints about how you can fix your code yourself.