Giter Site home page Giter Site logo

salehahmedshafin / k-nearest-neighbors-knn- Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 41 KB

KNN is a simple supervised machine learning algorithm used for classification and regression tasks. It predicts the label of a data point based on the majority class of its k nearest neighbors.

Jupyter Notebook 100.00%

k-nearest-neighbors-knn-'s Introduction

K-Nearest-Neighbors-KNN-

KNN is a simple supervised machine learning algorithm used for classification and regression tasks. It predicts the label of a data point based on the majority class of its k nearest neighbors.

K-Nearest Neighbors (KNN): Here is step by step on how to compute K-nearest neighbors KNN algorithm:

  1. Determine parameter K = number of nearest neighbors
  2. Calculate the distance between the query-instance and all the training samples
  3. Sort the distance and determine nearest neighbors based on the K-th minimum distance
  4. Gather the category of the nearest neighbors
  5. Use simple majority of the category of nearest neighbors as the prediction value of the query instance

Here's a step-by-step guide to achieving the tasks you've mentioned:

  1. Load and Plot Training Data:

Read data from "train.txt". Plot training points with different colored markers based on the assigned class label.

  1. Implement KNN Algorithm:

Implement the KNN algorithm with user-defined K. Classify the test points from "test.txt". Plot the test points with different colored markers based on the predicted class label.

  1. Write Predictions to "prediction.txt":

For each test data point, calculate distances and store the top K distances along with their class labels. Write the predictions to "prediction.txt" as described.

k-nearest-neighbors-knn-'s People

Contributors

salehahmedshafin avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.