KNN using Python from Scratch

This repository contains a Jupyter notebook that demonstrates the implementation of the K-Nearest Neighbors (KNN) algorithm entirely from scratch in Python. The KNN algorithm is a fundamental machine learning technique used for both classification and regression tasks. It is intuitive and easy to understand, making it an excellent algorithm for beginners to learn the basics of machine learning and pattern recognition.

Overview

The notebook provides a step-by-step guide to implementing the KNN algorithm, including:

  • Calculating Euclidean distance to measure the similarity between instances.
  • Finding the 'k' nearest neighbors to a given data point.
  • Making predictions based on the majority vote (for classification) or the average (for regression) of the nearest neighbors.

Prerequisites

To run this notebook, you will need:

  • Python 3.8 or later
  • Jupyter Notebook or JupyterLab

Installation

Follow these steps to set up your environment:

  1. Ensure that Python and Jupyter are installed on your system. If not, you can download and install them from Python's official website and Jupyter's official documentation.

  2. Clone this repository to your local machine:

git clone <https://github.com/MuhammadAliAhson/KNN-in-Python-from-scratch>

Medium Article