There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Hello, seems like the lesson misses explanation on how to solve question #3. I see the solution, but there is no explanation what is what. The way fn_rate formula is constructed is confusing.
#3. Calculate the false negative rate for each threshold
fn_rate = [1 - sum(y_pred_prob[y_test==1][:,1]>t)/pos_cases for t in thresh]
#Find the first threshold value where the is greater than 2 per 100
For anyone struggling with the poor explanation in part 3 of this exercise, I decided to rewrite the code provided in the solution into a function which I think is far more logical, albeit longer, given the context of the lesson so far including my comments on how each step works.
def get_min_thresh(y_pred_prob, min_false_negative_rate):
thresh = np.linspace(0, 1, 100) # creates array between 0 and 1
for t in thresh:
y_pred_class = (y_pred_prob[:,1] > t) * 1.0 # calculates predicted classes for given threshold
confusion = confusion_matrix(y_test, y_pred_class) # computes confusion matrix for given threshold
fn_rate = confusion[1,0] / (confusion[1,0] + confusion[1,1]) # fn_rate = fn / (fn + tp)
if fn_rate >= min_false_negative_rate:
print(f'Minimum Threshold for {min_false_negative_rate*100} false negatives per 100: {t:.2f}')
return t
get_min_thresh(y_pred_prob, 0.02) # returns 0.22 for fn rate of two per hundred positive cases
I hope this is enough until Codecademy update this lesson for more clarity and better understanding.
I’m not sure im getting the y_pred_class = (y_pred_prob[:,1]>0.25) * 1.0
part of this how does that code go through each item in y_pred_prob?
If that’s what its doing how is it then multiplying something like 9.44871111e-04 * 1 and getting 1 or 0