Git Product home page Git Product logo

dynamic-knn-gpu's Introduction


GPU based Dynamic k-Nearest Neighbours

I built a relatively simple implementation of a Dynamic k-NN using TensorFlow with GPU support.

knn from datacamp

In k-NN classification, the output is a class membership. An object is classified by a majority vote of its neighbors, >with the object being assigned to the class most common among its k nearest neighbors (k is a positive integer, >typically small). If k = 1, then the object is simply assigned to the class of that single nearest neighbor.

from wikipedia

A dynamic k-NN allows for some parameters (such as the k parameter) to be defined on a per instance basis, instead of being fixed in the model. This can be useful in cases where the k is influenceed by some independent variable or whenever you need to add new training instances without requiring a fit step to your model.

Note: running TensorFlow on GPU is formally supported for only NVIDIA cards (CUDA backend).

Benchmark Results

For more detailed information abuot the benchmark check out the notebook with the experimental information.

These were done on a laptop with a GTX 870m, the results could've been even better with a faster GPU.

TF GPU speedup over TF CPU:
1.4x

On large datasets, the GPU gains are more noticeable, however, even on a laptop, with a low powered GPU, the GPU performance gain can be around 40%.

TF GPU speedup over Scikit CPU (dynamic k):
50x

As seen above, the results are quite favorable towards the k-NN implementation using TensorFlow with GPU support.

In the scenario where the k is static or when no new training instances are introduced this implementation of k-NN using TensorFlow with GPU support can be around 20% slower than the Scikit implementation (assuming you are using their efficient implementation with Ball Tree). However, this is also the worst scenario for this model and with a better GPU this difference might decrease.

In any case, it's impressive that we can obtain such results for such a simple implementation!

Dependencies

Instructions

Run example with command:

python example.py

Author

João Leal

Related research:

Code License

Code is licensed under the Apache License 2.0

dynamic-knn-gpu's People

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.