Write a function from scratch called roc_curve_computer that accepts (in this exact order): a list of true labels a list of prediction probabilities (notice these are probabilities and not predictions - you will need to obtain the predictions from these probabilities) a list of threshold values. The function must compute and

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Compute and Plot the ROC Curve

Write a function from scratch called roc_curve_computer that accepts (in this exact order):

  • a list of true labels
  • a list of prediction probabilities (notice these are probabilities and not predictions - you will need to obtain the predictions from these probabilities)
  • a list of threshold values.

The function must compute and return the True Positive Rate (TPR, also called recall) and the False Positive Rate (FPR) for each threshold value in the threshold value list that is passed to the function.

Important: Be sure to reuse functions and code segments from your work above! You should reuse two of your above created functions so that you do not duplicate your code.

The function you will write behaves identically to Scikit-Learn's roc_curve function, except that it will take the list of thresholds in as input rather than return them as output. Your function must calculate one value of TPR and one value of FPR for each of the threshold values in the list.

Your function will output a list of TPR values and a list of FPR values (in that order). You will then take these TPR and FPR values, and plot them against each other to create the Receiver Operating Characteristic (ROC) curve.

You must not use any built-in library function to perform the calculation of a performance metric. You may of course use common, built-in Python functions, such as: range(), len(), et cetera.

Code Check: As an example, calling the roc_curve_computer function with the input true_labels = [1, 0, 1, 0, 0], pred_probs = [0.875, 0.325, 0.6, 0.09, 0.4], and thresholds = [0.00, 0.25, 0.50, 0.75, 1.00] yields the output:

TPR = [1.0, 1.0, 1.0, 0.5, 0.0] and FPR = [1.0, 0.6666, 0.0, 0.0, 0.0].

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY