Lecture 3.4 | KNN Algorithm In Machine Learning | K Nearest Neighbor | Classification | #mlt #knn
Summary
TLDRThis video introduces a significant machine learning algorithm called K-Nearest Neighbors (K-NN), focusing on its technical concepts and aspects. K-NN is an instance-based learning algorithm used for classification and regression tasks. The video explains the algorithm's process, from data preparation to prediction, highlighting how K-NN classifies new data points based on the majority class of its three nearest neighbors. It emphasizes the algorithm's simplicity and effectiveness in making predictions without building a model, relying on the concept of similarity and proximity.
Takeaways
- 😀 The video introduces an important machine learning algorithm called K-Nearest Neighbors (K-NN).
- 🔍 K-NN is a basic instance-based learning algorithm, used for both classification and regression tasks in machine learning.
- 📚 Instance-based learning involves storing instances of the training data and making predictions based on them without creating a general model.
- 📏 K-NN uses the concept of distance to determine the similarity between data points, with common distance metrics being Euclidean distance, Manhattan distance, and cosine similarity.
- 🔢 The 'k' in K-NN refers to the number of nearest neighbors considered for making a prediction, which is a critical parameter of the algorithm.
- 🧩 The algorithm works by finding the 'k' nearest neighbors to a new data point and then making a prediction based on the majority class of these neighbors.
- 🛠️ Preparing the data is an important step, which includes repairing and cleaning the data to ensure accurate predictions.
- 📊 The value of 'k' can significantly affect the performance of the K-NN algorithm, and there's no one-size-fits-all value; it often requires tuning.
- 📝 The script explains the process of classifying a new data point using K-NN, which involves calculating distances to find the nearest neighbors and then determining the class based on their majority.
- 📐 The concept of proximity is central to K-NN, where the algorithm assigns a new data point to the class that has the maximum number of its nearest neighbors.
- 🔑 K-NN is a non-parametric algorithm, meaning it makes no assumptions about the underlying data distribution and is flexible to various data sets.
Q & A
What is the main topic of the video?
-The main topic of the video is the K-Nearest Neighbors (KNN) algorithm, an important machine learning algorithm, and its related technical concepts and aspects.
What does KNN stand for?
-KNN stands for K-Nearest Neighbors, which is a type of instance-based learning, or lazy learning, where the function is only approximated at the prediction time.
What are the two main tasks for which KNN is used in machine learning?
-KNN is primarily used for classification and regression tasks in machine learning.
What is the concept of instance-based learning in the context of KNN?
-Instance-based learning in KNN refers to the algorithm storing the training dataset and making predictions based on the nearest neighbors of the input data point at the time of prediction, without creating a model.
What does the term 'parametric' mean in the context of the KNN algorithm?
-In the context of KNN, 'parametric' refers to the algorithm not making any assumptions about the data distribution, unlike non-parametric algorithms which do not make such assumptions.
How does KNN determine the similarity between data points?
-KNN determines the similarity between data points by calculating the distance between them, which can be Euclidean distance, Manhattan distance, or cosine similarity, among others.
What is the first step in preparing data for the KNN algorithm?
-The first step in preparing data for KNN is to repair and clean the data to ensure it is in a usable form for making predictions from the data road.
How does KNN decide the value of 'k', the number of neighbors to consider for prediction?
-The value of 'k' is determined by the square root of the number of data points (n), although there is no specific or preferred value, and it can be adjusted based on the dataset and problem.
What is the process of finding the nearest neighbors in KNN?
-In KNN, the algorithm calculates the distance from the prediction data point to all other data points, identifies the 'k' nearest neighbors, and then makes a prediction based on the majority class among these neighbors.
How does KNN make a prediction for a new data point?
-KNN makes a prediction for a new data point by finding the 'k' nearest neighbors of the point, calculating their distances, and then assigning the class that has the majority among these neighbors.
What is an example scenario where KNN would be used?
-An example scenario could be classifying a new data point represented by a black dot on a plot with features (60,60), determining whether it belongs to the blue or red class based on its nearest neighbors.
Outlines
🤖 Introduction to Machine Learning Algorithms
The video script begins with an introduction to an important machine learning algorithm called K-Nearest Neighbors (K-NN). It explains the basic concept of K-NN, which is an instance-based learning or non-parametric algorithm used for classification and regression tasks. The script discusses the idea of instance-based learning, where the algorithm stores the training data and makes predictions based on the nearest neighbors of the input data points. It also touches upon the concept of similarity and proximity in the context of K-NN, emphasizing how the algorithm classifies new data points based on the features of similar points in the training set.
📊 Understanding K-NN Algorithm and Data Classification
This paragraph delves deeper into the K-Nearest Neighbors algorithm, explaining the steps involved in its operation. It starts with data preparation, emphasizing the importance of having clean and usable data. The script then discusses the process of finding the nearest neighbors for a given data point, which involves calculating distances using various methods such as Euclidean distance, Manhattan distance, and cosine similarity. The paragraph also explains how the K-NN algorithm makes predictions by considering the majority class among the nearest neighbors. An example is provided to illustrate the classification of a new data point based on its proximity to the nearest neighbors, highlighting how the algorithm assigns the class with the highest representation among these neighbors.
Mindmap
Keywords
💡Machine Learning
💡k-Nearest Neighbors (k-NN)
💡Classification
💡Regression
💡Instance-based Learning
💡Distance Metrics
💡Proximity
💡Features
💡Neighbors
💡Prediction
💡Data Points
Highlights
Introduction to the K-Nearest Neighbors (KNN) algorithm and its importance in machine learning.
KNN is an instance-based learning algorithm used for classification and regression tasks in machine learning.
Explanation of instance-based learning, contrasting it with model-based learning.
Description of how KNN stores training data and uses it for predictions, emphasizing its instance-based nature.
Introduction to the concept of similarity in KNN, discussing proximity and distance between data points.
Explanation of how KNN calculates distances between data points using various metrics like Euclidean distance, Manhattan distance, and cosine similarity.
Discussion on the selection of the 'k' value in KNN, its impact on the algorithm's performance, and the use of the square root of 'n' as a general guideline.
Step-by-step process of preparing data for KNN, including data repair and cleaning.
Importance of selecting the right 'k' value and its mathematical calculation based on the number of data points.
Explanation of how KNN finds the nearest neighbors of a prediction data point and calculates their distances.
Process of classifying and predicting the class of a new data point based on its nearest neighbors.
Illustration of how KNN assigns the class of a new data point based on the majority class among its nearest neighbors.
Example of classifying a new data point in a dataset with features plotted on a graph, demonstrating the KNN algorithm in action.
Discussion on the practical application of KNN in real-world scenarios and its significance in machine learning models.
Highlighting the ease of implementation of KNN without the need for building complex models, making it accessible for various prediction tasks.
Final summary of the KNN algorithm, emphasizing its role in instance-based learning and its practical implications in machine learning.
Transcripts
हेलो एवरीवन वेलकम बैक और आज के इस वीडियो
में जो है हम हमारी मशीन लर्निंग
एल्गोरिथम की एक और इंपॉर्टेंट एल्गोरिथम
जिसका नाम है कैश नी उसको डिस्कस करने
वाले हैं और उसके रिलेटेड जितने भी
टेक्निकल कॉन्सेप्ट्स है एस्पेक्ट्स हैं
विद एग्जांपल हम उनको समझेंगे सो स्टार्ट
करते हैं केएन के साथ के केएन बेसिकली
होता क्या है तो केएन जिसकी फूल फॉर्म है
हमारी के नेरिस्ट नी यह बेसिक है हमारी
एल्गोरिथम है और ये एल्गोरिथम कौन सी है
ये एल्गोरिथम है हमारी इंस्टेंस बेस्ड
लर्निंग एल्गोरिथम जिसको हम उसे करते हैं
क्लासिफिकेशन और रिग्रेशन के टास्क के लिए
मशीन लर्निंग के अंदर अब यहां पर आपको
रिग्रेशन समझ में ए गया क्लासिफिकेशन समझ
में ए गया केएन एक एल्गोरिथम है ये समझ
में ए गया बट इसके अंदर एक टर्म है
इंस्टेंस बेस्ड लर्निंग इस इंस्टेंस
लर्निंग का मतलब क्या है इसको जो है
मेमोरी प्रीवियस वीडियो में कर कर चुका
हूं और वहां पर जो है मैंने मॉडल बेस
लर्निंग और इंस्टेंस बेस्ड लर्निंग जो
हमारी मशीन लर्निंग की एक टेक्निक होती है
क्लासिफिकेशन टेक्निक होती है मशीन
लर्निंग एल्गोरिदम्स की टाइप्स की उसको जो
है हमने वहां पर डिस्कस किया था बट यहां
पे आपको ओवरव्यू देने के लिए मैं बता देता
हूं इंस्टेंस बेस्ड लर्निंग ये वो लर्निंग
एल्गोरिथम होती है जिनके अंदर हम हमारे
मॉडल को जो है डेवलप नहीं करते जैसे की
पुरानी एल्गोरिदम्स के अंदर करते थे चाहे
वो रिग्रेशन हो क्लासिफिकेशन हो एवीएम हो
या फिर डिसीजन ट्री हो यहां पर हम क्या
करते हैं इंस्टेंस बेस्ड लर्निंग के अंदर
जो हमारा ट्रेनिंग डाटा होता है उसको
एल्गोरिथम स्टोर कर लेती है और डायरेक्टली
जब प्रिडिक्शन का टाइम आता है उसे टाइम पर
हम उसे उसे करते हैं विदाउट क्रिएटिंग ए
मॉडल और यह एल्गोरिथम जो है हमारी के
नियरेस्ट
पैरामेट्रिक एल्गोरिथम होती है और नॉन
पैरामेट्रिक का मीनिंग है यहां पर की इसके
अंदर हम हमारे डाटा डिस्ट्रीब्यूशन से
रिलेटेड यानी की डाटा से रिलेटेड डाटा सेट
से रिलेटेड
किसी भी प्रेयर असंपशन नहीं मानते हैं अब
यहां पर
मशीन के अंदर डिसीजन ट्री के अंदर हमने ये
मानना था जो हमारे डाटा सेट के फीचर्स हैं
पैरामीटर हैं वो बेसिकली क्या है
इंडिपेंडेंस तू इ अदर है यानी की वो एक
दूसरे पे डिपेंड नहीं करते और फाइनल
आउटपुट में जो है इक्वल कंट्रीब्यूशन
प्रोवाइड करते हैं बट यहां पर हमारे पास
कोई भी डाटा सेट हो कैसा भी डाटा सेट हो
हम इसके अंदर कोई भी पैरामीटर कोई भी
एजंप्शंस को जो है असम नहीं करते हमारे
डाटा से रिलेटेड जो हमारी केयर और
एल्गोरिथम है यह कम कैसे करती है तो जो
हमारी केन और एल्गोरिथम है ये बेसिकली
सिमिलर थिंग्स को यानी की सिमिलर डाटा
प्वाइंट्स को जो की आसपास है क्लोज
प्रॉक्सिमिटी में है यानी की वो डाटा
पॉइंट जो की नियर बाय है जिनके से फीचर्स
हैं उनको
से क्लास से बिलॉन्ग करते हैं अब इस लाइन
को जो है आप एक एग्जांपल की हेल्प से
समझेंगे जो की हम भी आपको बताऊंगा तो
हमारा कम करता है आइडिया ऑफ सिम्युलेरिटी
पर सिमिलरिटी जिसको हम जो डिस्टेंस के नाम
से भी जानते हैं प्रॉक्सिमिटी के नाम से
भी जानते हैं और क्लोज़नेस के नाम से भी
जानते हैं और इसको अगर मैथमेटिक्स की टर्म
में बात करें टेक्निकल टर्म में बात करें
जिसको हम कैसे कैलकुलेट करेंगे तो इसको हम
कैलकुलेट करते हैं भाई कैलकुलेटिंग डी
डिस्टेंस बिटवीन डाटा प्वाइंट्स ऑन ए
ग्राफ तो जो हमारे डाटा सेट के अंदर डाटा
प्वाइंट्स होते हैं वह डाटा प्वाइंट्स जो
सिमिलर होंगे यानी की नियर बाय होंगे एक
दूसरे के तो हमारी केन और जूम करती है की
वह से क्लास से बिलॉन्ग करते हैं और हमें
पता कैसे चलेगा की वो क्लोज है
प्रॉक्सिमिटी के अंदर है या नहीं है उसके
लिए जो हम डिस्टेंस कैलकुलेट करते हैं तो
यह था नल्गोरिदम का जनरल ओवरव्यू अब बात
करते हैं
सबसे पहले स्टेप्स होता है हमारा प्रिपेयर
डी डाटा सबसे पहले मैं डाटा को रिपेयर
करना है क्लीन करके ताकि जो है हम उसे
डाटा का यूटिली उसे कर सके तो गेट सम
प्रिडिक्शन फ्रॉम डेट रोड डाटा दूसरी इसके
अंदर हमारा स्टेप आता है
इसके अंदर जो के है वो जो है यहां पे उसकी
वैल्यू डिपेंड करती है की हमें हमारे डाटा
प्वाइंट्स के नियर जितने भी डाटा
प्वाइंट्स हैं वो कितने नेरिस्ट डाटा
पॉइंट फाइंड आउट करने हैं तो उसके लिए
वैल्यू ऑफ के मटर करता है और वैल्यू ऑफ के
को जो हम सिलेक्ट करते हैं विद डी हेल्प
ऑफ दिस फॉर्मूला डेट इस के = स्क्वायर रूट
ऑफ एन बट जनरली देखा जाए तो कोई भी ऐसी
केक की स्पेसिफिक या फिर प्रेफर्ड वैल्यू
नहीं है जिसका हम उसे कर सकते हैं बट एक
ओवरव्यू के लिए एक मैथमेटिकल एस्पेक्ट के
लिए की बेस्ट वैल्यू क्या हो शक्ति है
उसके लिए हम के को जो है इस फॉर्मूला से
कैलकुलेट कर लेते हैं जहां पर एन होता है
हमारा नंबर ऑफ डाटा प्वाइंट्स
है उसके अकॉर्डिंग
कोड नंबर को प्रेफर करते हैं ताकि हमारे
डाटा प्वाइंट्स का जो आउटपुट है वह इक्वल
ना हो क्लेश ना करें थर्ड स्टेप आता है
हमारा के नियरेस्ट नी अब के की वैल्यू जो
भी हमने असम की है और जो हमारा प्रिडिक्शन
डाटा पॉइंट है उसके नेरिस्ट जितने भी
नेबर्स होंगे यानी की जो हमारी केक की
वैल्यू होगी उतने नियरेस्ट नेबर्स को जो
हम फाइंड आउट करेंगे और दें उनका डिस्टेंस
कैलकुलेट करेंगे और डिस्टेंस कैलकुलेट
करने के लिए स्टैटिसटिकल या फिर
मैथमेटिकली बहुत सारे फॉर्मुलस हैं बट जो
कुछ पॉपुलर फॉर्मुलस है जो की केएनएल
एल्गोरिथम उसे करती है वह उसे करती है
हमारी उकलेडियन डिस्टेंस मैनहैटन डिस्टेंस
और कोसिन सिमिलरिटी फिफ्थ स्टेप आता है
क्लासीफाइड और प्रिडिक्ट अब हमें क्या
करना है जब डिस्टेंस कैलकुलेटर हो गया तो
अब हमें प्रिडिक्शन करनी है की किस तरीके
से हमारा डाटा पॉइंट नया डाटा पॉइंट नया
इनपुट किस क्लास को बिलॉन्ग करता है उसको
मैं क्लासीफाइड करना है
और दें लास्ट स्टेप के अंदर हमें आउटपुट
यानी की रिजल्ट हमें प्रोवाइड कर देना अब
बात करते हैं एग्जांपल के साथ और केएन को
अच्छे से समझते हैं तो सपोज मां लीजिए
हमारे पास एक डाटा सेट है जिसके कुछ
फीचर्स हैं डाटा प्वाइंट्स है जिसको मैंने
इस तरीके से प्लॉट कर दिया एस पर दे
फीचर्स अब इस डाटा सेट के अंदर हमें क्या
करना है एक नया डाटा पॉइंट क्लासीफाइड
करना है जो की ब्लैक डॉट से मैं यहां पे
रिप्रेजेंट करूंगा और उसकी फीचर वैल्यू
होगी 60 कॉम 60 यानी की इन वालुज पर जो है
मुझे क्या करना है एक नया डाटा पॉइंट एक
नया इनपुट जो है हमें हमारी मशीन को
प्रोवाइड करना है और हमारी मशीन को बताना
है यह जो डाटा पॉइंट इस पोजीशन पर आएगा यह
कौन सी क्लास से बिलॉन्ग करेगा क्या वो
ब्लू क्लास से बिलॉन्ग करेगा या फिर वो
रेड क्लास से बिलॉन्ग करेगा तो यहां पर
क्या है क्लासिफिकेशन
वैल्यू नहीं होती है बट आपको समझने के लिए
मैंने यहां पर
असम कर लिया अब के की वैल्यू थ्री का
मीनिंग है उसे ब्लैक डाटा पॉइंट जो की मैं
फाइंड आउट करना है यह जो डाटा पॉइंट जिसकी
वैल्यू जिसकी क्लास में फाइंड आउट करनी है
इसके नेरिस्ट थ्री डाटा प्वाइंट्स को जो
है अब हम यहां पे एस पर और एल्गोरिथम
फाइंड आउट करेंगे तो जब हमने तीन नेरिस्ट
डाटा पॉइंट आउट किया तो हमें जो है ये तीन
ऐसे नए डाटा प्वाइंट्स मिले जो की इस
ब्लैक डॉट के नेरिस्ट है और इनको जो है
हमने डिस्टेंस से कैलकुलेट कर लिया अब
हमें क्या करना है इन क्लास की जो वालुज
हैं यानी की ये जो हमारे तीन ईयर्ज डाटा
प्वाइंट्स मिले हमें विद डी हेल्प ऑफ के
वैल्यू अब इसकी हेल्प से हमें पता चल गया
की दो जो है हमारे नेरिस्ट वैल्यू रेड
क्लास से बिलॉन्ग करती है और सिर्फ एक
डाटा पॉइंट जो ब्लू क्लास से बिलॉन्ग करता
है तो यहां पर हमारी केन और गोवर्धन क्या
कर लेती है वह असम कर लेती है बिकॉज़ वो
सिमिलरिटी के कॉन्सेप्ट पर कम करती है
प्रॉक्सिमिटी के कॉन्सेप्ट पर कम करती है
तो इसके अकॉर्डिंग जो भी मैक्सिमम डाटा
प्वाइंट्स होंगे हमारे उसे नए इनपुट के
आसपास उसके नेरिस्ट उसकी जो है वह क्लास
प्रिडिक्ट कर देगी तो यहां पर एक ब्लू है
दो रेड है तो मेजॉरिटी यहां पे दो रेड
क्लासेस की है तो ये ब्लैक डाटा पॉइंट जो
है हमारा क्या हो जाएगा रेड क्लास से
असाइन हो जाएगा और हमें जो है हमारा फाइनल
आउटपुट मिल जाएगा क्या की ये जो ब्लैक डॉट
था ये जो हमारा नया इंस्टेंस डाटा पॉइंट
था ये हमारा बिलॉन्ग करता है रेडक्लास से
तो इस तरीके से अभी हमने क्या किया
इंस्टेंस बेस लर्निंग की एक इंपॉर्टेंट
एल्गोरिथम जिसका नाम है केएन डेट इस के
नियरेस्ट नी का उसे किया अब आप देखिए यहां
पे हमने किसी मॉडल को बिल्ड नहीं किया है
डायरेक्टली हमने क्या किया प्रिडिक्शन के
टाइम पे हमारे डाटा प्वाइंट्स को जो हमने
स्टोर किया था उनकी वैल्यू इसको उसे करके
प्रिडिक्शन कर दी थैंक यू
浏览更多相关视频
Python Exercise on kNN and PCA
StatQuest: K-nearest neighbors, Clearly Explained
Perceptron Learning Algorithm
All Learning Algorithms Explained in 14 Minutes
Week 2 Lecture 6 - Statistical Decision Theory - Classification
Types Of Machine Learning | Machine Learning Algorithms | Machine Learning Tutorial | Simplilearn
5.0 / 5 (0 votes)