Machine Learning Fundamentals: Bias and Variance — Transcript
Full transcript
- 0:00>> Hurricane Florence came
- 0:03by while I was working on StatQuest.
- 0:07Dark clouds filled the sky,
- 0:10but that didn't stop StatQuest.
- 0:14StatQuest. Hello/ I'm Josh Starmer
- 0:19and welcome to StatQuest.
- 0:21Today we're going to be talking about
- 0:22some machine learning fundamentals,
- 0:24bias, and variance
- 0:26and they're going to be clearly explained.
- 0:28Imagine we measured the weight and height of
- 0:32a bunch of mice and
- 0:33plotted the data on a graph.
- 0:35Light mice tend to be
- 0:37short and heavier mice tend to be taller.
- 0:42But after a certain weight,
- 0:44mice don't get any taller, just more obese.
- 0:47Given this data, we would like to
- 0:50predict mouse height given its weight.
- 0:52For example, if you
- 0:54told me your mouse weighed this much,
- 0:57then we might predict that
- 0:59the mouse is this tall.
- 1:01Ideally, we would know
- 1:03the exact mathematical formula that
- 1:05describes the relationship
- 1:06between weight and height.
- 1:08But in this case,
- 1:10we don't know the formula,
- 1:12so we're going to use
- 1:13two machine learning methods
- 1:14to approximate this relationship.
- 1:17However, I'll leave
- 1:19the true relationship curve
- 1:21in the figure for reference.
- 1:23The first thing we do is
- 1:25split the data into two sets,
- 1:26one for training
- 1:27the machine learning algorithms
- 1:29and one for testing them.
- 1:31The blue dots are the training set
- 1:34and the green dots are the testing set.
- 1:37Here is just the training set.
- 1:40The first machine learning algorithm that
- 1:43we will use is linear regression,
- 1:45AKA, least squares.
- 1:48Linear regression fits
- 1:50a straight line to the training set.
- 1:52Note. The straight line
- 1:55doesn't have the flexibility
- 1:56to accurately replicate the arc
- 1:58in the true relationship.
- 2:00No matter how we try to fit
- 2:02the line, it will never curve.
- 2:06Thus, the straight line will never
- 2:09capture the true relationship
- 2:11between weight and height,
- 2:12no matter how well we
- 2:13fit it to the training set.
- 2:15The inability for a
- 2:17machine learning method like
- 2:19linear regression to capture
- 2:21the true relationship is called bias.
- 2:24Because the straight line can't
- 2:26be curved like the true relationship,
- 2:29it has a relatively large amount of bias.
- 2:32Another machine learning method might
- 2:35fit a squiggly line to the training set.
- 2:38The squiggly line is super flexible and
- 2:41hugs the training set along
- 2:42the arc of the true relationship.
- 2:44Because the squiggly line can handle
- 2:47the arc in the true relationship
- 2:49between weight and height,
- 2:50it has very little bias.
- 2:52We can compare how well the straight line and
- 2:56the squiggly line fit
- 2:57the training set by
- 2:58calculating their sums of squares.
- 3:01In other words, we measure
- 3:03the distances from the fit lines to the data,
- 3:06square them, and add them up.
- 3:09They are squared so that
- 3:11negative distances do not
- 3:13cancel out positive distances.
- 3:15Notice how the squiggly line
- 3:18fits the data so well
- 3:19that the distances between
- 3:21the line and the data are all zero.
- 3:24In the contest to see
- 3:26whether the straight line
- 3:27fits the training set
- 3:29better than the squiggly line,
- 3:30the squiggly line wins.
- 3:33But remember, so far we've only
- 3:36calculated the sums of
- 3:38squares for the training set.
- 3:40We also have a testing set.
- 3:43Now let's calculate the sums
- 3:45of squares for the testing set.
- 3:47In the contest to
- 3:49see whether the straight line
- 3:50fits the testing set
- 3:52better than the squiggly line,
- 3:54the straight line wins.
- 3:57Even though the squiggly line did
- 3:59a great job fitting the training set,
- 4:02it did a terrible job
- 4:04fitting the testing set.
- 4:06In machine learning lingo,
- 4:08the difference in fits between
- 4:10datasets is called variance.
- 4:12The squiggly line has low bias,
- 4:15since it is flexible and can adapt to
- 4:17the curve in the relationship
- 4:19between weight and height.
- 4:21But the squiggly line has
- 4:23high variability because it
- 4:25results in vastly different sums
- 4:26of squares for different datasets.
- 4:29In other words, it's hard to predict how well
- 4:32the squiggly line will perform
- 4:34with future datasets.
- 4:35It might do well sometimes
- 4:37and other times it might do terribly.
- 4:41In contrast, the straight line
- 4:43has relatively high bias,
- 4:45since it cannot capture
- 4:47the curve in the relationship
- 4:48between weight and height.
- 4:50But the straight line
- 4:52has relatively low variance
- 4:54because the sums of squares are
- 4:55very similar for different datasets.
- 4:58In other words, the straight line might only
- 5:01give good predictions and
- 5:03not great predictions,
- 5:04but they will be consistently
- 5:06good predictions.
- 5:08Bam. Oh, no.
- 5:11Terminology alert.
- 5:13Because the squiggly line
- 5:14fits the training set really well,
- 5:16but not the testing set,
- 5:18we say that the squiggly line is overfit.
- 5:22In machine learning, the ideal algorithm has
- 5:25low bias and can
- 5:26accurately model the true relationship.
- 5:29And it has low variability by
- 5:32producing consistent predictions
- 5:34across different datasets.
- 5:36This is done by finding
- 5:38the sweet spot between
- 5:40a simple model and a complex model.
- 5:44Oh, no. Another terminology alert.
- 5:47Three commonly used methods
- 5:49for finding the sweet spot between
- 5:51simple and complicated models
- 5:53are regularization,
- 5:55boosting, and bagging.
- 5:58The StatQuest on a random forest show
- 6:01an example of bagging in action.
- 6:03And we'll talk about regularization
- 6:06and boosting in future StatQuests.
- 6:08Double bam. Hooray. We've made
- 6:13it to the end of another exciting StatQuest.
- 6:15If you like this StatQuest and
- 6:17want to see more, please subscribe.
- 6:19And if you want to support StatQuest,
- 6:21please consider buying one
- 6:23or two of my original songs.
- 6:25All right. Until next time, quest on.
About this transcript
This page contains the full transcript of Machine Learning Fundamentals: Bias and Variance by StatQuest with Josh Starmer, generated from the public captions YouTube serves with the video. The transcript has 884 words across 172 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 translate the transcript into 100+ languages.
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, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.