Giter Club home page Giter Club logo

clustering's Introduction

Clustering

This crate provides an easy and efficient way to perform kmeans clustering on arbitrary data. The algo is initialized with kmeans++ for best performance of the clustering.

There are three goals to this implementation of the kmeans algorithm:

  1. it must be generic
  2. it must be easy to use
  3. it must be reasonably fast

Important Note

Depending on your execution environment and the size of the dataset you aim to cluster; your code might benefit from parallelisation (this can mean massive performance improvements for large problems). Should you want to enable the multithreaded behavior, then add the "parallel" feature to your dependencies.

# To enable multithreading during clustering, add the "parallel" feature
# to your dependency.
[dependencies]
clustering = {version = "0.2.0", features = ["parallel"]}

# If all you aim for it a sequential clustering, just leave that feature out.
[dependencies]
clustering = {version = "0.2.0"}

Example

use clustering::*;

let n_samples    = 20_000; // # of samples in the example
let n_dimensions =    200; // # of dimensions in each sample
let k            =      4; // # of clusters in the result
let max_iter     =    100; // max number of iterations before the clustering forcefully stops

// Generate some random data
let mut samples: Vec<Vec<f64>> = vec![];
for _ in 0..n_samples {
    samples.push((0..n_dimensions).map(|_| rand::random()).collect::<Vec<_>>());
}

// actually perform the clustering
let clustering = kmeans(k, &samples, max_iter);

println!("membership: {:?}", clustering.membership);
println!("centroids : {:?}", clustering.centroids);

Features

This crate comes with two optional features:

  • parallel which enables multithreaded dispatch with rayon (thanks to @jean-pierreBoth 's contribution)
  • logging which you can use to log when clustering takes shortcuts.

clustering's People

Contributors

xgillard avatar jean-pierreboth 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.