Question: Online Coding Test || Only 20 minutes remaining You are given two arrays, one with predicted scores from a logistic regression based classifier and another
Online Coding Test || Only 20 minutes remaining
You are given two arrays, one with predicted scores from a logistic regression based classifier and another with true class labels. Note that, the scores from the classifier can be converted to the conditional probability of the class label being 1 given an input x using the sigmoid function (defined below for your reference). Given a threshold value t, we consider the predicted value to be 1 if the predicted probability is greater than t and 0 otherwise. You need to write a function to compute accuracy, precision and recall of the classifier, given a threshold.
For reference, here are the definitions of accuracy, precision and recall and here is the definition of the sigmoid function.
In other words, Accuracy: fraction of data points where the predicted label and the true label agree relative to all data points. Precision: fraction of data points where the predicted label and the true label agree relative to data points where the predicted label is 1. Recall: fraction of data points where the predicted label and the true label agree relative to data points where the true label is 1.
Finally, given a score s, we get the P(=1x)=11+esP(label=1x)=1+es1 (i.e. the sigmoid function)
-
[execution time limit] 4 seconds (py)
-
[input] array.float scores
Predicted scores from the logistic regression based classifier
-
[input] array.integer binary_labels
True labels (each entry is either 1 or 0)
-
[input] float threshold
Threshold probability
-
[output] array.float
Array of length 3 where the first index is accuracy, second index is precision, third index is recall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
