Writing our own K Nearest Neighbors in Code - Practical Machine Learning Tutorial with Python p.17

TL;DR
This content discusses the implementation of a K nearest neighbors function, including the calculation of Euclidean distance. It also mentions the use of numpy and compares the function to scikit-learn's K nearest neighbors algorithm.
Transcript
what is going on everybody and welcome to part 17 of our machine learning tutorial series we've been working on K nearest neighbors and let's get into it don't want to waste any more time here so we've started creating this K nearest neighbors function all we've done so far though is just warn the user when they're trying to do something stupid so ... Read More
Key Insights
- 👈 Creating a K nearest neighbors function involves calculating Euclidean distances between a prediction point and other data points.
- 💨 Numpy arrays can be used to perform a faster version of Euclidean distance calculation.
- 😥 The function appends distances to a list and sorts it to find the K nearest data points.
- 👥 The most common group is determined using the Counter object from the collections module.
Install to Summarize YouTube Videos and Get Transcripts
Explore YouTube Video Summarizer or Get YouTube Transcript Extractor
Questions & Answers
Q: What is the purpose of the K nearest neighbors function?
The K nearest neighbors function is used to calculate the K nearest data points to a prediction point based on the comparison of Euclidean distances.
Q: What is the problem with K nearest neighbors when comparing data points?
The problem is that K nearest neighbors requires comparing the prediction point to all other points in the dataset, making it a slow calculation.
Q: How can the Euclidean distance calculation be improved?
Numpy arrays can be used to perform a faster calculation of Euclidean distance, with a simplified version also available. This saves time and allows for calculations in higher dimensions.
Q: How is the most common group determined in the K nearest neighbors function?
The K nearest neighbors function uses the Counter object from Python's collections module to determine the most common group, taking into account the K nearest data points.
Summary & Key Takeaways
-
The content focuses on creating a K nearest neighbors function and discusses the problem of comparing a data point to other data points to find the closest ones.
-
It explains different versions of the Euclidean distance calculation, including a faster method using numpy arrays.
-
The content also covers appending distances to a list, sorting the list, and obtaining the most common group.
-
Lastly, it mentions the intention to compare the function to scikit-learn's K nearest neighbors algorithm in the next tutorial.
Read in Other Languages (beta)
Share This Summary 📚
Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator
Explore More Summaries from sentdex 📚






Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator