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

clusterizr

v0.8.14

Published

Hey, show me all the posts that were generated around the same story!

Downloads

1

Readme

CLUSTERIZR FOR NODEJS

Hey, show me all the posts that were generated around the same story!

Clusterizr is a simplified adaptation of HAC Divisive algorithm. It is good to bring common problems to the ground like:

  • Finding posts revolving around the same story by linking them hierarchically through tags
  • Determining trending tweets that are referring to the same story using tweet hashtags
  • Finding co-originating Tumblr/9GAG/Wordpress/Reddit etc. posts
  • Discovering YouTube videos that were made about the same content
  • Just cluster anything that is characterized by tags

How it works?

This implementation of HAC is divisive where the flat clustering criteria is equal and linking criteria is fully contained subset. When you choose hierarchical clustering, you would try to find not similar items, but items originating from the same root.

For example the way people would tag an image where a dog barks while running after a cat is hierarchical in the following sense: some would only tag by ['dog','cat'] some would add more granularity by using ['dog','cat','running'] and some would completely describe the image by using ['dog','cat','bark','running','chase']. But all originate from the same root. However if you had another picture about a dog chasing a car, people would usually do the same classification. However a solely statistical method would find the two image the same because dog, chase, running are pretty similar, only the cat is missing from the picture.

HAC algorithm with complete subset linkage criterion guarantees you, that you would only see items in the same cluster, if they are originating from the same root. This way you can have like two trending topics about Kim Kardashian, both are about her making a selfie about her booty ass in front of a car, however one happened in Miami, and another did happen in LA in a bus stop. Thus there would be a lot of images with the tags [bus, bus stop, kardashian, selfie, miami, ass, beach, sand, la, car, camaro, funny, photo, celeb] varying in length and count. A statistical system would identify usually one trend about selfie and Kardashian, not distinguishing that there were basically two stories present on the same day.

Divisive HAC with complete containment model will try to find clusters with a [minimum_cluster_size] with the possible most tags. It does this by first classifying all items by their tag counts. This will create a simple ordered list starting from the item with the most and ending with the item with the least tag counts. Then it creates levels, putting items on the same level with the same count of tags. For example post_a with tags [x,y,z] will go to level 3 just as post_b with tags [a,b,c]. Then an algorithm will start to find clusters, starting with items on the highest level.

If an item has similar items on the same level, it merges it. During same level merge if the item count will be larger than the minimum_cluster_size, then this cluster is finished. If not, the algorighm will go to the lower level with this item, and tries to find an item that is totally contained by it. For example lets say, minimum_cluster_size is 2, [x,y,z] on level 3 would be a cluster with size 1 (because did not match [a,b,c]) and [y,z] on level 2 will be merged. The cluster size will be 2. If it fits the condition then the recursion stops. If on level 2 there wasn't [y,z] but on level 1 there is [z] then it will be merged with that. Root found and minimum cluster size reached.

If we think that levels with too big distance should not be merged, we can add a [maximum_level_distance] option, so if it would be 2 in the example above, [x,y,z] and [z] would not be merged into one cluster.

Version

0.8.14

References

  • [https://en.wikipedia.org/wiki/Hierarchical_clustering] - Hierarchical clustering

Installation

$ npm install clusterizr

Usage

var clusterizr = require("clusterizr");
var posts = [
	{p_data: {tags: ["dog"]}},
	{p_data: {tags: ["dog", "jump"]}},
	{p_data: {tags: ["dog", "eat"]}},
	{p_data: {tags: ["cat", "eat"]}},
	{p_data: {tags: ["dog", "bark", "jump"]}},
	{p_data: {tags: ["dog", "bark", "run"]}},
	{p_data: {tags: ["cat", "eat", "moan"]}},
	{p_data: {tags: ["cat", "jump", "milk"]}},
	{p_data: {tags: ["cat", "eat", "milk"]}},
	{p_data: {tags: ["dog", "bark", "run", "leash"]}},
	{p_data: {tags: ["dog", "whine", "sit", "sleep"]}}
];

var opts = {
    minimum_cluster_size:10,
    maximum_level_distance:10,
    can_debug:false
}

clusterizr.process(posts, opts, function (err, results) {
    console.log(results);
})

outputs

statistics: [{gid: 7, level: 3, post_count: 1, tags: [Object]},
			 {gid: 3, level: 2, post_count: 3, tags: [Object]},
			 {gid: 0, level: 1, post_count: 7, tags: [Object]}],
items: [{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 0},
		{p_data: [Object], gid: 3},
		{p_data: [Object], gid: 3},
		{p_data: [Object], gid: 3},
		{p_data: [Object], gid: 7}]

statistics parameter shows that 3 clusters were detected, the first has 1 post (cat, jump and milk were not able to be merged to any cluster because ['cat','eat'] is not compatible with ['cat','jump','milk'] and there were no single ['cat'] root, and this HAC implementation intentionally won't merge ['cat','eat] with ['cat','jump'] or ['cat','milk'] since they are different 'stories'. items parameter shows the original input items list with an additional gid parameter. Items that belong to the same group have the same gid, so it can be processed comfortably.

Happy clustering! If you need more elaborate options and a different implementation, I kindly suggest Clusterfck.