CPSC 330 Lecture 9: Classification Metrics

Firas Moosvi (Slides adapted from Varada Kolhatkar)

Announcements

  • Important information about midterm 1 released on this Piazza post
  • Practice Midterm will be released today!
    • We hope to give you a sense of the exam format, types of questions, and to get you more familiar with the PrairieLearn interface. They do NOT encompass all the topics we’ve discussed nor reflect the actual number of questions on the actual midterm.
    • It will have a limit of 50-mins so you can get used to how the system will behave in the CBTF BUT the practice midterm has NOT been designed to be completed in 50 minutes!
    • You will be able to do the practice midterm multiple times for practice (but the practice MT questions are not randomized)
    • As promised, documentation for numpy, pandas, scipy, and sklearn is provided to you as the first question.
  • HW4 has been released. Due next week Monday.
  • HW5 will be released next week Tuesday. It’s a project-type assignment and you get till Oct 28th to work on it.

ML workflow

Classification Metrics

At the end of last class we talked about some of the problems with “accuracy”, and we brainstormed some possible alternatives, and saw that there are tonnes of options.

Today, let’s sift through the noise and develop some intuition about why we need classification metrics, and how some of them are used.

Example from StatQuest!

Let’s first walk through this example through StatQuest with obese mice and classifying them using Logistic Regression:

Source: StatQuest

Activity 1: Create Confusion Matrix

Source: StatQuest

Activity 2: Calculate Precision, Recall, Specificity

  • Recall (aka Sensitivity in biomedical literature)
    • TP/(TP+FN)
  • Precision
    • TP/(TP+FP)
  • Specificity
    • TN/(TN+FP)

Break!

Let’s take a 10 minute break.

Confusion matrix questions

Imagine a spam filter model where emails classified as spam are labeled 1 and non-spam emails are labeled 0. If a spam email is incorrectly classified as non-spam, what is this error called?

    1. A false positive
    1. A true positive
    1. A false negative
    1. A true negative

Confusion matrix questions

In an intrusion detection system, intrusions are identified as 1 and non-intrusive activities as 0. If the system fails to identify an actual intrusion, wrongly categorizing it as non-intrusive, what is this type of error called?

    1. A false positive
    1. A true positive
    1. A false negative
    1. A true negative

Confusion matrix questions

In a medical test for a disease, diseased states are labeled as 1 and healthy states as 0. If a healthy patient is incorrectly diagnosed with the disease, what is this error known as?

    1. A false positive
    1. A true positive
    1. A false negative
    1. A true negative

iClicker Exercise 9.1

iClicker cloud join link: https://join.iclicker.com/VYFJ

Select all of the following statements which are TRUE.

    1. In medical diagnosis, false positives are more damaging than false negatives (assume “positive” means the person has a disease, “negative” means they don’t).
    1. In spam classification, false positives are more damaging than false negatives (assume “positive” means the email is spam, “negative” means they it’s not).
    1. If method A gets a higher accuracy than method B, that means its precision is also higher.
    1. If method A gets a higher accuracy than method B, that means its recall is also higher.

Counter examples

Method A - higher accuracy but lower precision

Negative Positive
90 5
5 0

Method B - lower accuracy but higher precision

Negative Positive
80 15
0 5

Thresholding Exercise 9.2

iClicker cloud join link: https://join.iclicker.com/VYFJ

Select all of the following statements which are TRUE.

    1. If we increase the classification threshold, both true and false positives are likely to decrease.
    1. If we increase the classification threshold, both true and false negatives are likely to decrease.
    1. Lowering the classification threshold generally increases the model’s recall.
    1. Raising the classification threshold can improve the precision of the model if it effectively reduces the number of false positives without significantly affecting true positives.

ROC AUC questions

Consider the points A, B, and C in the following diagram, each representing a threshold. Which threshold would you pick in each scenario?

    1. If false positives (false alarms) are highly costly
    1. If false positives are cheap and false negatives (missed true positives) highly costly
    1. If the costs are roughly equivalent

Source

Next Class: Dr. Giulia Toti !

I’ll be covering CPSC 430 for that prof, so Dr. Toti will be covering my section.

Have fun!