-
Notifications
You must be signed in to change notification settings - Fork 280
Open
Labels
Description
Algorithm Name
KNN - Algorithm ( machine learning )
Programming Language
Python
Category
Other
Difficulty Level
Medium (Intermediate)
Algorithm Description
-Nearest Neighbors (KNN) - Simple Implementation from Scratch
This script implements a basic version of the KNN algorithm for classification
using only Python and NumPy (no sklearn).
Concept Summary:
- KNN is a supervised learning algorithm used for classification & regression.
- It finds the K nearest data points to a test point using a distance metric
(usually Euclidean distance). - For classification → predicts the majority label among neighbors.
- For regression → predicts the average value among neighbors.
- It is a lazy learner (no explicit training phase, prediction happens at query time).
Steps in this code:
- Compute Euclidean distance between the test point and all training points.
- Sort training points by their distance to the test point.
- Select top 'k' nearest points.
- Use majority voting to determine the predicted class.
- Return the predicted label.
Author / Contributor:
💻 Contributed by: Lakhinana Chaturvedi Kashyap
References (Optional)
No response
Contribution Intent
- I would like to implement this algorithm myself
- I'm requesting this for someone else to implement
- I need help implementing this algorithm
Code of Conduct
- I agree to follow this project's Code of Conduct
Reactions are currently unavailable