Pradeepsingh61/DSA_Code

Add Knn algo in machine learning

Ouverte

#643 ouverte le 20 oct. 2025

 (1 commentaire) (0 réaction) (1 personne assignée)C++ (266 forks)auto 404
algorithmsenhancementhacktoberfestnew-language

Métriques du dépôt

Stars
 (52 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

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:

  1. KNN is a supervised learning algorithm used for classification & regression.
  2. It finds the K nearest data points to a test point using a distance metric (usually Euclidean distance).
  3. For classification → predicts the majority label among neighbors.
  4. For regression → predicts the average value among neighbors.
  5. It is a lazy learner (no explicit training phase, prediction happens at query time).

Steps in this code:

  1. Compute Euclidean distance between the test point and all training points.
  2. Sort training points by their distance to the test point.
  3. Select top 'k' nearest points.
  4. Use majority voting to determine the predicted class.
  5. 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

Guide contributeur