Machine Learning Fundamentals: Cross Validation — Transcript
Full transcript
- 0:00StatQuest
- 0:01Check it out
- 0:03talking about
- 0:05Machine-learning. Yeah StatQuest
- 0:08Check it out
- 0:09Talking about cross-validation
- 0:12StatQuest
- 0:15Hello, I'm Josh stormer and welcome to StatQuest today we're going to talk about cross validation and it's gonna be clearly explained
- 0:25Okay, let's start with some data
- 0:28We want to use the variables chest pain good blood circulation
- 0:33Etc
- 0:34To predict if someone has heart disease
- 0:37Then when a new patient shows up
- 0:40we can measure these variables and
- 0:43Predict if they have heart disease or not
- 0:47However, first we have to decide which machine learning method would be best
- 0:53we could use logistic regression or
- 0:56K nearest neighbors
- 0:59Or support vector machines and
- 1:03Many more machine learning methods. How do we decide which one to use?
- 1:09Cross-validation allows us to compare different machine learning methods and get a sense of how well they will work in practice
- 1:19Imagine that this blue column represented all of the data that we have collected about people with and without heart disease
- 1:27We need to do two things with this data
- 1:30One we need to estimate the parameters for the machine learning methods in
- 1:36In other words to use logistic regression we have to use some of the data to estimate the shape of this curve
- 1:44in machine learning lingo
- 1:47Estimating parameters is called training the algorithm
- 1:51The second thing we need to do with this data is evaluate how well the machine learning methods work in?
- 1:58Other words we need to find out if this curve will do a good job categorizing new data in
- 2:06In machine learning lingo
- 2:09Evaluating a method is called testing the algorithm
- 2:13Thus using machine learning lingo we need the data to
- 2:18one train the machine learning methods and
- 2:22to test the machine learning methods a
- 2:27A terrible approach would be to use all the data to estimate the parameters ie to train the algorithm
- 2:35Because then we wouldn't have any data left to test the method
- 2:40Reusing the same data for both training and
- 2:43Testing is a bad idea because we need to know how the method will work on data. It wasn't trained on a
- 2:52Slightly better idea would be to use the first seventy-five percent of the data for training and the last 25% of the data for testing
- 3:02We could then compare methods by seeing how well each one categorized the test data
- 3:09But how do we know that using the first?
- 3:11Seventy-five percent of the data for training in the last 25% of the data for testing is the best way to divide up the data
- 3:21What if we use the first 25% of the data for testing
- 3:26Or what about one of these middle blocks?
- 3:29Rather than worry too much about which block would be best for testing cross-validation uses them all one at a time and summarizes the results at the end
- 3:41For example cross-validation would start by using the first three blocks to train the method and
- 3:49then use the last block to test the method and
- 3:53Then it keeps track of how well the method did with the test data
- 3:58then it uses this combination of blocks to train the method and
- 4:03this block is used for testing and
- 4:07Then it keeps track of how well the method did with the test data, etc
- 4:12Etc, etc
- 4:16in the end every block of data is used for testing and we can compare methods by seeing how well they performed in
- 4:25This case since the support vector machine did the best job classifying the test data sets. We'll use it
- 4:33BAM!!!
- 4:36Note: in this example, we divided the data into 4 blocks. This is called four-fold cross validation
- 4:45However, the number of blocks is arbitrary
- 4:49In an extreme case we could call each individual patient (or sample) a block
- 4:56This is called "Leave One Out Cross Validation"
- 4:59Each sample is tested individually
- 5:03That said in practice it is very common to divide the data into ten blocks. This is called 10-fold cross-validation
- 5:14Double BAM!!!
- 5:16One last note before we're done
- 5:20Say like we wanted to use a method that involved a tuning parameter a parameter that isn't estimated but is just sort of guessed
- 5:28For example Ridge regression has a tuning parameter
- 5:33Then we could use 10-fold cross validation
- 5:36to help find the best value for that tuning parameter
- 5:40Tiny Bam!
- 5:42Hooray we've made it to the end of another exciting StatQuest if you like this StatQuest and want to see more please subscribe
- 5:50And if you want to support StatQuest well
- 5:54Please click the like button down below and consider buying one of my original songs
- 5:59Alright until next time quest on
About this transcript
This page contains the full transcript of Machine Learning Fundamentals: Cross Validation by StatQuest with Josh Starmer, generated from the public captions YouTube serves with the video. The transcript has 780 words across 72 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.