Aniket Mishra
banner
avyakta.bsky.social
Aniket Mishra
@avyakta.bsky.social
I'm Simplifying Concepts of Artificial Intelligence, Machine Learning, Internet of things, and Web Development.

📩 for Collaboration
Welcome
November 21, 2024 at 7:45 PM
End of the thread
_______
That's a wrap. Every day I simplify complex concepts around Python, Machine Learning & Language Models.

Follow me to ensure you don't miss that.

Like and share the first post to support my work and help this reach more people
November 21, 2024 at 7:31 PM
Steps to implement the K-NN algorithm:

Data Pre-processing step

Fitting the K-NN algorithm to the Training set

Predicting the test result

Test accuracy of the result(Creation of Confusion matrix)

Visualizing the test set result.

12/12 🧵🧵
November 21, 2024 at 7:30 PM
Disadvantages of KNN Algorithm:

Always needs to determine the value of K which may be complex some time

The computation cost is high because of calculating the distance between the data points for all the training samples

11/12 🧵👇
November 21, 2024 at 7:30 PM
Advantages of KNN

It is simple to implement

It is robust to the noisy training data

It can be more effective if the

training data is large

10/12 🧵👇
November 21, 2024 at 7:30 PM
Multiple way to determine the best value for K

try some values to find the best out of them

most preferred value for K is 5

low value as K=1 or K=2, can be noisy & lead to the effects of outliers in the model

Large values are good but it may find some difficulties

9/12🧵👇
November 21, 2024 at 7:30 PM
Firstly, we will choose the number of neighbors, so we will choose the k=5

Next, we will calculate the Euclidean distance between the data points

The Euclidean distance is the distance between two points

8/12 🧵👇
November 21, 2024 at 7:29 PM
Step-4: Among these k neighbors, count the number of the data points in each category

Step-5: Assign the new data points to that category for which the number of the neighbor is maximum

Step-6: Our model is ready.

7/12 🧵👇
November 21, 2024 at 7:29 PM
How does K-NN work?

The K-NN working can be explained on the basis of the below algorithm:

1: Select the number K of the neighbors

2: Calculate the Euclidean distance of K number of neighbors

3: Take the K nearest neighbors as per the calculated Euclidean distance

6/12 🧵👇
November 21, 2024 at 7:29 PM
Suppose there are two categories, i.e., Category A and Category B, and we have a new data point x1

To solve this type of problem, we need a K-NN algorithm.

With the help of K-NN, we can easily identify the category or class of a particular dataset

5/12 🧵👇
November 21, 2024 at 7:28 PM
It is a non-parametric algorithm, which means it does not make any assumption on underlying data.

also called a lazy learner algorithm

does not learn from the training set immediately instead it stores the dataset
at the time of classification, it performs an action

4/12 🧵👇
November 21, 2024 at 7:28 PM
when new data appears then it classifies into a well suite category by using K- NN algorithm

K-NN algorithm can be used for Regression as well as for Classification but mostly it is used for the Classification problems

3/12 🧵👇
November 21, 2024 at 7:28 PM
K-NN algorithm assumes the similarity between the new case data & available cases

put the new case into the category that is most similar to the available categories

K-NN algorithm stores all the available data and classifies a new data point based on the similarity

2/12 🧵👇
November 21, 2024 at 7:27 PM