GithubHelp home page GithubHelp logo

mansafreo / primitive-knn-in-javascript Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 62 KB

A simple KNN algorithm in Javascript that can be used to classify data

JavaScript 100.00%
ai analytics data data-science javascript knn knn-algorithm knn-classification machine-learning machine-learning-algorithms javascript-ai-algorithms knn-javascript knn-from-scratch

primitive-knn-in-javascript's Introduction

K-Nearest Neighbour Algorithm in Javascript

Introduction

KNN is a machine learning algorithm that uses instance-based learning to classify items/data into groups. By instance-based learning, it means that the algorithm does not produce a model per se but uses stored data/examples(instances) to classify the data it is given. As such , having labelled data is important. The algorithm works by calculating the distances between data and selecting a given number K (the hyperparameter) of neighbours(closest points) and classifying the new point as the majority class near it.

Steps

Preparing the Data

The training data has to be labelled and with the appropriate classes. The number of attributes that will be used to classify the data( the feature matrix) gives the dimensionality of the data. For example, if we used this algorithm to classify fruits e.g. apples and oranges, we might use features such as the diameter, weight, colour , acidity and texture. This gives us a dimensionality of 5. The fruits have other attributes like smell, taste and number of seeds but we have picked only those 5 of interest.

This gives us a sample feature matrix [ diameter, weight, colour , acidity, texture]
However, note that the features are usually represented as numerical data. If the attributes are text, data encoding is done to convert the text into meaningful numeric data that can be used in the algorithm The data is usually split into the training data and the test data

Datasets Used

Diabetes KNN

primitive-knn-in-javascript's People

Contributors

mansafreo avatar

Watchers

 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.