Machine Learning Fundamentals: Sensitivity and Specificity — Transcript
Full transcript
- 0:00when the well runs dry you might be
- 0:04thirsty but this still StatQuest you
- 0:07can watch it StatQuest hello I'm Josh
- 0:13Starmar and welcome to StatQuest today
- 0:15we're gonna continue our series on
- 0:17machine learning fundamentals and we're
- 0:19going to talk about sensitivity and
- 0:21specificity they're gonna be clearly
- 0:23explained this StatQuest follows up on
- 0:27the one that describes the confusion
- 0:29matrix so if you're not already down
- 0:31with that
- 0:32check out the quest the first half of
- 0:35this video will explain how to calculate
- 0:37and interpret sensitivity and
- 0:40specificity when you have a confusion
- 0:42matrix with two rows and two columns and
- 0:45the second half will show you how to
- 0:47calculate and interpret sensitivity and
- 0:50specificity when you have three or more
- 0:52rows and columns
- 0:55even if you're already down with the
- 0:57confusion matrix let's remember that
- 0:59rows correspond to what was predicted
- 1:01and columns correspond to the known
- 1:05truth when there are only two categories
- 1:09to choose from in this case the two
- 1:11choices were has heart disease or does
- 1:14not have heart disease then the top
- 1:17left-hand corner contains the true
- 1:19positives true positives are patients
- 1:23that had heart disease that were also
- 1:25predicted to have heart disease true
- 1:29negatives are in the bottom right hand
- 1:30corner true negatives are patients that
- 1:34did not have heart disease and were
- 1:36predicted not to have heart disease the
- 1:40bottom left-hand corner contains the
- 1:42false negatives false negatives are when
- 1:45a patient has heart disease but the
- 1:48prediction said they didn't lastly the
- 1:52top right hand corner contains the false
- 1:54positives false positives are patients
- 1:57that do not have heart disease but the
- 1:59prediction says that they do once we
- 2:03filled out the confusion matrix we can
- 2:05calculate two useful metrics sensitivity
- 2:09and specificity in this case sensitivity
- 2:13tells us what percentage of patients
- 2:15with heart disease were correctly
- 2:18identified
- 2:20sensitivity is the true positives
- 2:23divided by the sum of the true positives
- 2:26and the false negatives
- 2:29specificity tells us what percentage of
- 2:32patients without heart disease were
- 2:34correctly identified specificity are the
- 2:39true negatives divided by the sum of the
- 2:42true negatives and the false positives
- 2:46in the StatQuest on the confusion
- 2:48matrix we applied logistic regression to
- 2:51a testing data set and ended up with
- 2:55this confusion matrix let's start by
- 2:59calculating sensitivity for this
- 3:01logistic regression here's the formula
- 3:05for sensitivity and for true positives
- 3:08we plug in 139 and for false negatives
- 3:13we plug in 32 when we do the math we get
- 3:18zero point eight one sensitivity tells
- 3:22us that 81% of the people with heart
- 3:25disease were correctly identified by the
- 3:27logistic regression model
- 3:30now let's calculate the specificity
- 3:34here's the formula for specificity and
- 3:37for true negatives we will plug in 112 and
- 3:42for false positives we will plug in 20 when
- 3:47we do the math we get 0.85 specificity
- 3:52tells us that 85% of the people without
- 3:55heart disease were correctly identified
- 3:58by the logistic regression model now
- 4:02let's calculate sensitivity and
- 4:03specificity for the random forest model
- 4:06that we used in the confusion matrix
- 4:08StatQuest
- 4:10here's the confusion matrix here's the
- 4:14formula for sensitivity and when we plug
- 4:17in the numbers we get zero point eight
- 4:19three
- 4:21here's the formula for specificity and
- 4:24when we plug in the numbers we get zero
- 4:27point eight three again
- 4:30now we can compare the sensitivity and
- 4:33specificity values that we calculated
- 4:35for the logistic regression to the
- 4:38values we calculated for the random
- 4:40forest
- 4:42sensitivity tells us that the random
- 4:45forest is slightly better at correctly
- 4:47identifying positives which in this case
- 4:50are patients with heart disease
- 4:54specificity tells us that logistic
- 4:56regression is slightly better correctly
- 4:59identifying negatives which in this case
- 5:02are patients without heart disease we
- 5:06would choose the logistic regression
- 5:08model
- 5:08if correctly identifying patients
- 5:10without heart disease was more important
- 5:13than correctly identifying patients with
- 5:15heart disease
- 5:18alternatively we would choose the random
- 5:21forest model if correctly identifying
- 5:23patients with heart disease was more
- 5:26important than correctly identifying
- 5:28patients without heart disease BAM
- 5:33in the confusion matrix stat quest we
- 5:36calculated this confusion matrix when we
- 5:39tried to predict someone's favorite movie
- 5:42now let's talk about how to calculate
- 5:44sensitivity and specificity when we have
- 5:47a confusion matrix with three rows and
- 5:49three columns the big difference when
- 5:53calculating sensitivity and specificity
- 5:55for larger confusion matrices is that
- 5:59there are no single values that work for
- 6:01the entire matrix instead we calculate a
- 6:06different sensitivity and specificity
- 6:07for each category
- 6:11so for this confusion matrix we'll need
- 6:14to calculate sensitivity and specificity
- 6:16for the movie troll 2 for the movie Gore
- 6:20police and for the movie cool as ice
- 6:25let's start by calculating sensitivity
- 6:28for troll 2 for troll 2 there were 12
- 6:32true positives people that were
- 6:35correctly predicted to love troll 2 more
- 6:38than Gore police and cool as ice
- 6:41so for true positives we'll plug in 12
- 6:46and there were 112 plus 83 which equals
- 6:50195 false negatives people that love to
- 6:55troll 2 but were predicted to love
- 6:57Gore police or cool as ice
- 7:00so for false negatives will plug in 195
- 7:04and when we do the math we get 0.06
- 7:11sensitivity for troll 2 tells us that
- 7:13only 6% of the people that loved the
- 7:16movie troll 2 more than Gore police or
- 7:19cool as ice were correctly identified
- 7:22now let's calculate the specificity for
- 7:25troll 2 there were 23 plus 77 plus 92
- 7:31plus 17 equals 209 true negatives people
- 7:36that were correctly predicted to like
- 7:38Gore police or cool as ice more than
- 7:41troll 2 so for true negatives will plug
- 7:45in 209
- 7:47and there were 102 plus 93 equals 195
- 7:52false positives people that loved gore
- 7:55police or cool as ice the most but were
- 7:59predicted to love troll 2 so for false
- 8:02positives will plug in 195 and when we
- 8:07do the math we get 0.52 specificity
- 8:12for troll 2 tells us that 52% of the
- 8:16people who loved Gore police or cool as
- 8:18ice more than troll 2 were correctly
- 8:21identified
- 8:23calculating sensitivity and specificity
- 8:26for Gore police is very similar let's
- 8:30start by calculating sensitivity
- 8:34there are 23 true positives people that
- 8:37were correctly predicted to love Gore
- 8:39police the most
- 8:42and 102 plus 92 equals 194 false
- 8:47negatives people who loved Gore police
- 8:50the most but were predicted to love
- 8:52troll 2 or cool as ice more when we do the
- 8:56math we get 0.11 sensitivity
- 9:01for Gore police tells us that only 11%
- 9:04of the people that loved Gore police
- 9:06were correctly identified now let's
- 9:10calculate specificity there were 12 plus
- 9:1493 plus 83 plus 17 equals 205 true
- 9:19negatives people correctly identified as
- 9:22loving troll 2 or cool as ice more than
- 9:25gore police
- 9:27and 112 plus 77 equals 189 false
- 9:32positives people predicted to love gore
- 9:35police even though they didn't and when
- 9:39we do the math we get 0.52 specificity
- 9:44for gore police tells us that 52% of the
- 9:47people that loved troll 2 or cool as
- 9:50ice more than gore police were correctly
- 9:52identified
- 9:54lastly calculating sensitivity and
- 9:57specificity for cool as ice follows the
- 10:00same steps we identify the true
- 10:03positives the false positives the true
- 10:07negatives and the false negatives and
- 10:11then plug in the numbers first for
- 10:15sensitivity then for specificity double bam
- 10:20if we had a confusion matrix with
- 10:24four rows and four columns then we would
- 10:28have to calculate sensitivity and
- 10:29specificity for four different
- 10:31categories little bam
- 10:38in summary sensitivity equals the true positives
- 10:41divided by the sum of the true positives
- 10:44and the false negatives and specificity
- 10:48equals the true negatives divided by the
- 10:51sum of the true negatives and the false
- 10:53positives we can use sensitivity and
- 10:57specificity to help us decide which
- 11:00machine learning method would be best
- 11:02for our data if correctly identifying
- 11:06positives is the most important thing to
- 11:08do with the data we should choose a
- 11:10method with higher sensitivity if
- 11:13correctly identifying negatives is more
- 11:16important then we should put more
- 11:17emphasis on specificity
- 11:21hooray we've made it to the end of
- 11:23another exciting StatQuest if you like
- 11:26this StatQuest and want to see more
- 11:28please subscribe and if you want to
- 11:30support stack quest well consider buying
- 11:33one or two of my original songs alright
- 11:35until next time quest on
About this transcript
This page contains the full transcript of Machine Learning Fundamentals: Sensitivity and Specificity by StatQuest with Josh Starmer, generated from the public captions YouTube serves with the video. The transcript has 1,392 words across 226 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.