Pradeepsingh61/DSA_Code

Add Knn algo in machine learning

开放

#643 创建于 2025年10月20日

 (1 条评论) (0 个反应) (1 位负责人)C++ (266 个派生)auto 404
algorithmsenhancementhacktoberfestnew-language

仓库指标

星标
 (52 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南