K-NN ( K Nearest Neighbor )
KNN Algorithm

K-NN ( K Nearest Neighbor )

Hey folks, I hope you're doing well. KNN stands out as one of the fundamental algorithms in machine learning. It classifies a data point based on how its neighbors are classified (???? ???? ???? ???? ).


It's a simple machine learning algorithm employed for both classification and regression. KNN is a supervised learning model with several characteristics:

  • Majority Vote: The classification is based on the majority class of its neighbors.
  • No Training: KNN does not involve a training phase; all the work happens during query time.
  • Non-parametric: It doesn't make any assumptions about the underlying data distribution.


The 'K' in KNN represents the number of nearest neighbors used to classify new data points. Selecting the right 'K' is crucial. Often, it's recommended to set 'K' as the square root of 'n,' where 'n' is the total size of the data. It's advisable to use an odd 'K' to avoid ties in classification.


Euclidean distance is commonly used to calculate the nearest neighbors. For two points (x, y) and (a, b), the Euclidean distance (d) is calculated as follows:

d=((x?a)2)+((y?b)2)d=((x?a)2)+((y?b)2)


To practice and see the usage of this model, you can check out my mini-project on GitHub with just a simple click. But first take a look at the the basics.





abdelaati EL HRECH

Engineering student at IMT NORD EUROPE

1 年

Interesting ??

Chaymae Majdoubi

Air Traffic Safety Electronics Engineer (ATSEP)

1 年

Lol, that's amazing, keep up the good work ????????

Hamza SAHSAH ????

PhD Candidate in Blockchain and AI autonomous systems & Software Engineer | python developer

1 年

I understand it faster than that s5 course ???? , thanks hamza

要查看或添加评论,请登录

Hamza Fatnaoui的更多文章

  • OS module in python

    OS module in python

    The os library in Python provides a way for developers to interact with the operating system. Imagine Python, a new…

  • File and Error Handling

    File and Error Handling

    Hello there File is just an object that is created in our operating system. File can be a source code, video and photo.

  • What Is Web Scraping?

    What Is Web Scraping?

    Hey there! I hope you are doing well. You, like me, are an internet user with access to millions of websites that share…

  • The Average of The Averages is The Average

    The Average of The Averages is The Average

    Hey there! I hope you are doing well. Have you ever wondered how scientists can draw conclusions about a big group by…

  • The difference between A Data Analyst and A Data scientist?

    The difference between A Data Analyst and A Data scientist?

    hello folks, hope you are doing well A Data analyst: "As a student at AIAC University, my teacher asked me to 'provide…

  • What Is Supervised Learning and What Is Unsupervised Learning?

    What Is Supervised Learning and What Is Unsupervised Learning?

    Hey folks Supervised Learning: Let's say i am playing with a small kid of age 3.I took two devices in-front of him…

  • Mastering the Art of Data Preparation: A Fundamental Step in Data Science

    Mastering the Art of Data Preparation: A Fundamental Step in Data Science

    Hello folks The first part of any data science project is preparing your data, which means making sure its in the right…

社区洞察

其他会员也浏览了