npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jbeuckm/k-means-js

v0.5.0

Published

A basic Javascript implementation of the cluster analysis algorithm.

Downloads

6

Readme

K-Means Clustering

Build Status

A basic Javascript implementation of the [cluster analysis] 1 algorithm.

Usage

  • Optionally, normalize the data.

The normalizer will scale numerical data between [0,1] and will generate n outputs of either zero or one for discrete data, eg. category.

// Tell the normalizer about the category field.
var params = {
   category: "discrete"
};

// Category is a discrete field with two possible values.
// Value is a linear field with continuous possible values.
var data = [
    {
       category: "a",
       value: 25
    },
    {
       category: "b",
       value: 7.6
    },
    {
       category: "a",
       value: 28
    }
];


var ranges = require('dataset').findRanges(params, data);
var normalized = require('dataset').normalize(data, ranges);
  • Run the algorithm.
// This non-normalized sample data with n=k is a pretty awful example.
var points = [
  [.1, .2, .3],
  [.4, .5, .6],
  [.7, .8, .9]
];

var k = 3;

var means = require('kmeans').algorithm(points, k, console.log);

The call to algorithm() will find the data's range in each dimension, generate k=3 random points, and iterate until the means are static.

  • Find the best K

The method described by Pham, et al. is implemented. The algorithm evaluates K-means repeatedly for different values of K, and returns the best (guess) value for K as well as the set of means found during evaluation.

var pbk = require('phamBestK');

var maxKToTest = 10;
var result = pbk.findBestK(points, maxKToTest);

console.log("this data has "+result.K+" clusters");
console.log("cluster centroids = "+result.means);
  • Denormalize data

Denormalization can be used to show the means discovered:

for (var i= 0, l=result.means.length; i<l; i++) {
    console.log(dataset.denormalizeDatum(result.means[i], ranges));
}

Todo

  • denormalize data
  • provide ability to label data points, dimensions and means
  • build an asynchronous version of the algorithm