Lecture 3.4 | KNN Algorithm In Machine Learning | K Nearest Neighbor | Classification | #mlt #knn

Tech Master Edu
9 Jun 202308:44

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

00:00

🤖 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.

05:00

📊 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

Machine Learning is a subset of artificial intelligence that provides systems the ability to learn from data, improving their accuracy and performance without being explicitly programmed. In the context of the video, it is the overarching theme as the script discusses an important machine learning algorithm and its related technical concepts.

💡k-Nearest Neighbors (k-NN)

k-Nearest Neighbors is a type of instance-based learning algorithm used for both classification and regression tasks. The script introduces k-NN as a fundamental algorithm in machine learning, emphasizing its role in making predictions based on the 'nearest' training examples in the feature space.

💡Classification

Classification is the task of predicting the category or class of an entity based on its features. The script mentions classification as one of the primary tasks for which the k-NN algorithm is used, where the algorithm classifies new data points into predefined classes.

💡Regression

Regression is a type of predictive modeling technique that estimates the relationship between variables. While the script does not delve deeply into regression, it acknowledges it as another task for which machine learning algorithms, including k-NN, can be applied.

💡Instance-based Learning

Instance-based learning is a learning paradigm where the model is built from the training data itself, and predictions are made by comparing new data points to the training instances. The script explains that k-NN is an instance-based learning algorithm that stores the training data and uses it directly for making predictions.

💡Distance Metrics

Distance Metrics are used to quantify how far apart two data points are in a feature space. The script discusses the importance of distance metrics like Euclidean distance, Manhattan distance, and Cosine similarity in determining the 'nearest' neighbors in the context of the k-NN algorithm.

💡Proximity

Proximity refers to the closeness of data points. The script uses the term 'proximity' to describe how the k-NN algorithm considers the nearness of data points to determine the class of a new data point based on the majority class of its nearest neighbors.

💡Features

Features are the characteristics or attributes of data that are used as input to the machine learning model. The script mentions features in the context of data points and how they are used by the k-NN algorithm to find similar data points and classify new instances.

💡Neighbors

In the context of the k-NN algorithm, 'neighbors' refers to the data points that are closest to a new data point in the feature space. The script explains how the algorithm identifies the 'k' nearest neighbors to make a classification or regression prediction.

💡Prediction

Prediction is the process of estimating an output for a new data point based on learned patterns from the training data. The script describes the prediction step in the k-NN algorithm, where the class of a new data point is determined by the majority class of its nearest neighbors.

💡Data Points

Data points are individual entries or instances within a dataset, characterized by their features. The script frequently refers to data points, especially when explaining how the k-NN algorithm uses the nearest data points to make predictions.

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

play00:00

हेलो एवरीवन वेलकम बैक और आज के इस वीडियो

play00:03

में जो है हम हमारी मशीन लर्निंग

play00:05

एल्गोरिथम की एक और इंपॉर्टेंट एल्गोरिथम

play00:08

जिसका नाम है कैश नी उसको डिस्कस करने

play00:11

वाले हैं और उसके रिलेटेड जितने भी

play00:13

टेक्निकल कॉन्सेप्ट्स है एस्पेक्ट्स हैं

play00:16

विद एग्जांपल हम उनको समझेंगे सो स्टार्ट

play00:19

करते हैं केएन के साथ के केएन बेसिकली

play00:21

होता क्या है तो केएन जिसकी फूल फॉर्म है

play00:24

हमारी के नेरिस्ट नी यह बेसिक है हमारी

play00:27

एल्गोरिथम है और ये एल्गोरिथम कौन सी है

play00:30

ये एल्गोरिथम है हमारी इंस्टेंस बेस्ड

play00:32

लर्निंग एल्गोरिथम जिसको हम उसे करते हैं

play00:35

क्लासिफिकेशन और रिग्रेशन के टास्क के लिए

play00:37

मशीन लर्निंग के अंदर अब यहां पर आपको

play00:40

रिग्रेशन समझ में ए गया क्लासिफिकेशन समझ

play00:43

में ए गया केएन एक एल्गोरिथम है ये समझ

play00:46

में ए गया बट इसके अंदर एक टर्म है

play00:48

इंस्टेंस बेस्ड लर्निंग इस इंस्टेंस

play00:50

लर्निंग का मतलब क्या है इसको जो है

play00:53

मेमोरी प्रीवियस वीडियो में कर कर चुका

play00:55

हूं और वहां पर जो है मैंने मॉडल बेस

play00:58

लर्निंग और इंस्टेंस बेस्ड लर्निंग जो

play01:00

हमारी मशीन लर्निंग की एक टेक्निक होती है

play01:03

क्लासिफिकेशन टेक्निक होती है मशीन

play01:05

लर्निंग एल्गोरिदम्स की टाइप्स की उसको जो

play01:08

है हमने वहां पर डिस्कस किया था बट यहां

play01:10

पे आपको ओवरव्यू देने के लिए मैं बता देता

play01:13

हूं इंस्टेंस बेस्ड लर्निंग ये वो लर्निंग

play01:16

एल्गोरिथम होती है जिनके अंदर हम हमारे

play01:19

मॉडल को जो है डेवलप नहीं करते जैसे की

play01:22

पुरानी एल्गोरिदम्स के अंदर करते थे चाहे

play01:24

वो रिग्रेशन हो क्लासिफिकेशन हो एवीएम हो

play01:27

या फिर डिसीजन ट्री हो यहां पर हम क्या

play01:30

करते हैं इंस्टेंस बेस्ड लर्निंग के अंदर

play01:33

जो हमारा ट्रेनिंग डाटा होता है उसको

play01:35

एल्गोरिथम स्टोर कर लेती है और डायरेक्टली

play01:37

जब प्रिडिक्शन का टाइम आता है उसे टाइम पर

play01:39

हम उसे उसे करते हैं विदाउट क्रिएटिंग ए

play01:42

मॉडल और यह एल्गोरिथम जो है हमारी के

play01:45

नियरेस्ट

play01:48

पैरामेट्रिक एल्गोरिथम होती है और नॉन

play01:51

पैरामेट्रिक का मीनिंग है यहां पर की इसके

play01:54

अंदर हम हमारे डाटा डिस्ट्रीब्यूशन से

play01:56

रिलेटेड यानी की डाटा से रिलेटेड डाटा सेट

play01:59

से रिलेटेड

play02:00

किसी भी प्रेयर असंपशन नहीं मानते हैं अब

play02:03

यहां पर

play02:06

मशीन के अंदर डिसीजन ट्री के अंदर हमने ये

play02:10

मानना था जो हमारे डाटा सेट के फीचर्स हैं

play02:12

पैरामीटर हैं वो बेसिकली क्या है

play02:15

इंडिपेंडेंस तू इ अदर है यानी की वो एक

play02:18

दूसरे पे डिपेंड नहीं करते और फाइनल

play02:20

आउटपुट में जो है इक्वल कंट्रीब्यूशन

play02:22

प्रोवाइड करते हैं बट यहां पर हमारे पास

play02:25

कोई भी डाटा सेट हो कैसा भी डाटा सेट हो

play02:27

हम इसके अंदर कोई भी पैरामीटर कोई भी

play02:30

एजंप्शंस को जो है असम नहीं करते हमारे

play02:33

डाटा से रिलेटेड जो हमारी केयर और

play02:36

एल्गोरिथम है यह कम कैसे करती है तो जो

play02:39

हमारी केन और एल्गोरिथम है ये बेसिकली

play02:41

सिमिलर थिंग्स को यानी की सिमिलर डाटा

play02:44

प्वाइंट्स को जो की आसपास है क्लोज

play02:47

प्रॉक्सिमिटी में है यानी की वो डाटा

play02:49

पॉइंट जो की नियर बाय है जिनके से फीचर्स

play02:52

हैं उनको

play02:54

से क्लास से बिलॉन्ग करते हैं अब इस लाइन

play02:57

को जो है आप एक एग्जांपल की हेल्प से

play02:59

समझेंगे जो की हम भी आपको बताऊंगा तो

play03:02

हमारा कम करता है आइडिया ऑफ सिम्युलेरिटी

play03:05

पर सिमिलरिटी जिसको हम जो डिस्टेंस के नाम

play03:07

से भी जानते हैं प्रॉक्सिमिटी के नाम से

play03:09

भी जानते हैं और क्लोज़नेस के नाम से भी

play03:12

जानते हैं और इसको अगर मैथमेटिक्स की टर्म

play03:14

में बात करें टेक्निकल टर्म में बात करें

play03:16

जिसको हम कैसे कैलकुलेट करेंगे तो इसको हम

play03:19

कैलकुलेट करते हैं भाई कैलकुलेटिंग डी

play03:22

डिस्टेंस बिटवीन डाटा प्वाइंट्स ऑन ए

play03:24

ग्राफ तो जो हमारे डाटा सेट के अंदर डाटा

play03:26

प्वाइंट्स होते हैं वह डाटा प्वाइंट्स जो

play03:29

सिमिलर होंगे यानी की नियर बाय होंगे एक

play03:32

दूसरे के तो हमारी केन और जूम करती है की

play03:35

वह से क्लास से बिलॉन्ग करते हैं और हमें

play03:38

पता कैसे चलेगा की वो क्लोज है

play03:40

प्रॉक्सिमिटी के अंदर है या नहीं है उसके

play03:42

लिए जो हम डिस्टेंस कैलकुलेट करते हैं तो

play03:45

यह था नल्गोरिदम का जनरल ओवरव्यू अब बात

play03:48

करते हैं

play03:50

सबसे पहले स्टेप्स होता है हमारा प्रिपेयर

play03:54

डी डाटा सबसे पहले मैं डाटा को रिपेयर

play03:56

करना है क्लीन करके ताकि जो है हम उसे

play03:59

डाटा का यूटिली उसे कर सके तो गेट सम

play04:01

प्रिडिक्शन फ्रॉम डेट रोड डाटा दूसरी इसके

play04:05

अंदर हमारा स्टेप आता है

play04:09

इसके अंदर जो के है वो जो है यहां पे उसकी

play04:13

वैल्यू डिपेंड करती है की हमें हमारे डाटा

play04:16

प्वाइंट्स के नियर जितने भी डाटा

play04:17

प्वाइंट्स हैं वो कितने नेरिस्ट डाटा

play04:19

पॉइंट फाइंड आउट करने हैं तो उसके लिए

play04:21

वैल्यू ऑफ के मटर करता है और वैल्यू ऑफ के

play04:24

को जो हम सिलेक्ट करते हैं विद डी हेल्प

play04:26

ऑफ दिस फॉर्मूला डेट इस के = स्क्वायर रूट

play04:28

ऑफ एन बट जनरली देखा जाए तो कोई भी ऐसी

play04:32

केक की स्पेसिफिक या फिर प्रेफर्ड वैल्यू

play04:35

नहीं है जिसका हम उसे कर सकते हैं बट एक

play04:38

ओवरव्यू के लिए एक मैथमेटिकल एस्पेक्ट के

play04:40

लिए की बेस्ट वैल्यू क्या हो शक्ति है

play04:42

उसके लिए हम के को जो है इस फॉर्मूला से

play04:45

कैलकुलेट कर लेते हैं जहां पर एन होता है

play04:47

हमारा नंबर ऑफ डाटा प्वाइंट्स

play04:52

है उसके अकॉर्डिंग

play05:00

कोड नंबर को प्रेफर करते हैं ताकि हमारे

play05:02

डाटा प्वाइंट्स का जो आउटपुट है वह इक्वल

play05:04

ना हो क्लेश ना करें थर्ड स्टेप आता है

play05:07

हमारा के नियरेस्ट नी अब के की वैल्यू जो

play05:10

भी हमने असम की है और जो हमारा प्रिडिक्शन

play05:12

डाटा पॉइंट है उसके नेरिस्ट जितने भी

play05:15

नेबर्स होंगे यानी की जो हमारी केक की

play05:17

वैल्यू होगी उतने नियरेस्ट नेबर्स को जो

play05:19

हम फाइंड आउट करेंगे और दें उनका डिस्टेंस

play05:22

कैलकुलेट करेंगे और डिस्टेंस कैलकुलेट

play05:25

करने के लिए स्टैटिसटिकल या फिर

play05:27

मैथमेटिकली बहुत सारे फॉर्मुलस हैं बट जो

play05:30

कुछ पॉपुलर फॉर्मुलस है जो की केएनएल

play05:32

एल्गोरिथम उसे करती है वह उसे करती है

play05:34

हमारी उकलेडियन डिस्टेंस मैनहैटन डिस्टेंस

play05:37

और कोसिन सिमिलरिटी फिफ्थ स्टेप आता है

play05:41

क्लासीफाइड और प्रिडिक्ट अब हमें क्या

play05:43

करना है जब डिस्टेंस कैलकुलेटर हो गया तो

play05:45

अब हमें प्रिडिक्शन करनी है की किस तरीके

play05:47

से हमारा डाटा पॉइंट नया डाटा पॉइंट नया

play05:50

इनपुट किस क्लास को बिलॉन्ग करता है उसको

play05:52

मैं क्लासीफाइड करना है

play05:54

और दें लास्ट स्टेप के अंदर हमें आउटपुट

play05:56

यानी की रिजल्ट हमें प्रोवाइड कर देना अब

play05:59

बात करते हैं एग्जांपल के साथ और केएन को

play06:01

अच्छे से समझते हैं तो सपोज मां लीजिए

play06:04

हमारे पास एक डाटा सेट है जिसके कुछ

play06:06

फीचर्स हैं डाटा प्वाइंट्स है जिसको मैंने

play06:08

इस तरीके से प्लॉट कर दिया एस पर दे

play06:10

फीचर्स अब इस डाटा सेट के अंदर हमें क्या

play06:14

करना है एक नया डाटा पॉइंट क्लासीफाइड

play06:16

करना है जो की ब्लैक डॉट से मैं यहां पे

play06:19

रिप्रेजेंट करूंगा और उसकी फीचर वैल्यू

play06:22

होगी 60 कॉम 60 यानी की इन वालुज पर जो है

play06:26

मुझे क्या करना है एक नया डाटा पॉइंट एक

play06:29

नया इनपुट जो है हमें हमारी मशीन को

play06:32

प्रोवाइड करना है और हमारी मशीन को बताना

play06:34

है यह जो डाटा पॉइंट इस पोजीशन पर आएगा यह

play06:38

कौन सी क्लास से बिलॉन्ग करेगा क्या वो

play06:40

ब्लू क्लास से बिलॉन्ग करेगा या फिर वो

play06:43

रेड क्लास से बिलॉन्ग करेगा तो यहां पर

play06:45

क्या है क्लासिफिकेशन

play06:54

वैल्यू नहीं होती है बट आपको समझने के लिए

play06:56

मैंने यहां पर

play06:59

असम कर लिया अब के की वैल्यू थ्री का

play07:02

मीनिंग है उसे ब्लैक डाटा पॉइंट जो की मैं

play07:04

फाइंड आउट करना है यह जो डाटा पॉइंट जिसकी

play07:07

वैल्यू जिसकी क्लास में फाइंड आउट करनी है

play07:09

इसके नेरिस्ट थ्री डाटा प्वाइंट्स को जो

play07:11

है अब हम यहां पे एस पर और एल्गोरिथम

play07:14

फाइंड आउट करेंगे तो जब हमने तीन नेरिस्ट

play07:17

डाटा पॉइंट आउट किया तो हमें जो है ये तीन

play07:20

ऐसे नए डाटा प्वाइंट्स मिले जो की इस

play07:22

ब्लैक डॉट के नेरिस्ट है और इनको जो है

play07:25

हमने डिस्टेंस से कैलकुलेट कर लिया अब

play07:28

हमें क्या करना है इन क्लास की जो वालुज

play07:31

हैं यानी की ये जो हमारे तीन ईयर्ज डाटा

play07:33

प्वाइंट्स मिले हमें विद डी हेल्प ऑफ के

play07:35

वैल्यू अब इसकी हेल्प से हमें पता चल गया

play07:37

की दो जो है हमारे नेरिस्ट वैल्यू रेड

play07:40

क्लास से बिलॉन्ग करती है और सिर्फ एक

play07:43

डाटा पॉइंट जो ब्लू क्लास से बिलॉन्ग करता

play07:45

है तो यहां पर हमारी केन और गोवर्धन क्या

play07:48

कर लेती है वह असम कर लेती है बिकॉज़ वो

play07:50

सिमिलरिटी के कॉन्सेप्ट पर कम करती है

play07:52

प्रॉक्सिमिटी के कॉन्सेप्ट पर कम करती है

play07:54

तो इसके अकॉर्डिंग जो भी मैक्सिमम डाटा

play07:57

प्वाइंट्स होंगे हमारे उसे नए इनपुट के

play07:59

आसपास उसके नेरिस्ट उसकी जो है वह क्लास

play08:02

प्रिडिक्ट कर देगी तो यहां पर एक ब्लू है

play08:04

दो रेड है तो मेजॉरिटी यहां पे दो रेड

play08:07

क्लासेस की है तो ये ब्लैक डाटा पॉइंट जो

play08:09

है हमारा क्या हो जाएगा रेड क्लास से

play08:11

असाइन हो जाएगा और हमें जो है हमारा फाइनल

play08:14

आउटपुट मिल जाएगा क्या की ये जो ब्लैक डॉट

play08:17

था ये जो हमारा नया इंस्टेंस डाटा पॉइंट

play08:19

था ये हमारा बिलॉन्ग करता है रेडक्लास से

play08:22

तो इस तरीके से अभी हमने क्या किया

play08:24

इंस्टेंस बेस लर्निंग की एक इंपॉर्टेंट

play08:27

एल्गोरिथम जिसका नाम है केएन डेट इस के

play08:29

नियरेस्ट नी का उसे किया अब आप देखिए यहां

play08:32

पे हमने किसी मॉडल को बिल्ड नहीं किया है

play08:34

डायरेक्टली हमने क्या किया प्रिडिक्शन के

play08:37

टाइम पे हमारे डाटा प्वाइंट्स को जो हमने

play08:38

स्टोर किया था उनकी वैल्यू इसको उसे करके

play08:40

प्रिडिक्शन कर दी थैंक यू

Rate This

5.0 / 5 (0 votes)

関連タグ
Machine LearningK-NN AlgorithmClassificationRegressionInstance-BasedData PointsDistance CalculationNeighborhoodPredictive ModelingAlgorithm Overview
英語で要約が必要ですか?