Question: 1.a: Compute average empirical loss Assume we have a sample of NV patients for which a test outputs the following confusion matrix: Decision = 0

1.a: Compute average empirical loss Assume we have a sample of NV patients for which a test outputs the following confusion matrix: Decision = 0 Decision = 1 Reality = 0 TN FP Reality = 1 FN TP Compute the average loss this procedure incurs by summing up the losses for every mis-diagnosis and then dividing by the total number of tests. [2] : # TODO: fill in def compute_average_loss (results_dictionary, factor_k) : Function that computes average loss for a given confusion matrix and a multiplicaltive k_factor that compares the consequences of false nagatives and false positives. Inputs : results_dictionary : a dictionary with the counts of TP, FP, TN and FN k_factor : float, quantifies the ratio of the negative consequences of false negatives compared to false positives Outputs : average_loss : float TP count = results_dictionary [ 'TP_count' ] FP_count = results_dictionary [ 'FP_count' ] IN count = results_dictionary [ 'TN_count' ] FN count = results_dictionary [ 'FN_count' ] average_loss return ( average_loss) [3] : # Running validation tests: Do not modify res_dict = {'TP_count' : 100, 'FP_count' : 20, 'TN_count' : 450, 'FN_count' : 30} k_factors = [0, 10, 100] hash_list = ['ab51c1986c756154d0e3feb4f5a5e829', '91f25a837f3db78306b0ad2ef0437ff9' , '3fc1803a77013426e67076041de152db' ] for i, k in enumerate (k_factors) : average_loss = compute_average_loss (res_dict, k) print ( "For k = {}, the average loss is {: .3f}". format (k, average_loss) ) assert hash_list [i] == get_hash (average_loss ) print ( 'Test passed! ' )
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
