Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
density-clustering
Advanced tools
The density-clustering npm package provides algorithms for clustering data points based on their density. It includes popular clustering algorithms such as DBSCAN, OPTICS, and KMEANS, which are useful for identifying clusters in data sets where the clusters may have irregular shapes or varying densities.
DBSCAN
DBSCAN (Density-Based Spatial Clustering of Applications with Noise) is a popular clustering algorithm that groups together points that are closely packed together, marking as outliers points that lie alone in low-density regions. The code sample demonstrates how to use the DBSCAN algorithm to cluster a simple dataset.
const clustering = require('density-clustering');
const dbscan = new clustering.DBSCAN();
const dataset = [[1,2], [2,3], [2,2], [8,7], [8,8], [25,80]];
const clusters = dbscan.run(dataset, 2, 2);
console.log(clusters);
OPTICS
OPTICS (Ordering Points To Identify the Clustering Structure) is an algorithm that creates an ordering of the database that represents its density-based clustering structure. The code sample shows how to use the OPTICS algorithm to cluster a dataset.
const clustering = require('density-clustering');
const optics = new clustering.OPTICS();
const dataset = [[1,2], [2,3], [2,2], [8,7], [8,8], [25,80]];
const clusters = optics.run(dataset, 2, 2);
console.log(clusters);
KMEANS
KMEANS is a well-known clustering algorithm that partitions the dataset into K clusters, where each data point belongs to the cluster with the nearest mean. The code sample demonstrates how to use the KMEANS algorithm to cluster a dataset into 3 clusters.
const clustering = require('density-clustering');
const kmeans = new clustering.KMEANS();
const dataset = [[1,2], [2,3], [2,2], [8,7], [8,8], [25,80]];
const clusters = kmeans.run(dataset, 3);
console.log(clusters);
The ml-kmeans package provides an implementation of the K-means clustering algorithm. It is specifically focused on K-means and offers a simple and efficient way to perform K-means clustering. Compared to density-clustering, ml-kmeans is more specialized and does not offer other clustering algorithms like DBSCAN or OPTICS.
The hdbscan package is an implementation of the HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise) algorithm. It is designed to handle varying densities and can find clusters of varying shapes and sizes. Compared to density-clustering, hdbscan focuses on a more advanced density-based clustering algorithm and does not include KMEANS.
The clusterfck package provides several clustering algorithms, including hierarchical clustering, K-means, and DBSCAN. It offers a broader range of clustering methods compared to density-clustering, but may not be as specialized in density-based clustering algorithms like OPTICS.
Package contains popular methods for cluster analysis in data mining:
Density-based spatial clustering of applications with noise (DBSCAN) is one of the most popular algorithm for clustering data.
http://en.wikipedia.org/wiki/DBSCAN
Ordering points to identify the clustering structure (OPTICS) is an algorithm for clustering data similar to DBSCAN. The main difference between OPTICS and DBSCAN is that it can handle data of varying densities.
http://en.wikipedia.org/wiki/OPTICS_algorithm
Important
Clustering returned by OPTICS is nearly indistinguishable from a clustering created by DBSCAN. To extract different density-based clustering as well as hierarchical structure you need to analyse reachability plot generated by OPTICS.
For more information visit http://en.wikipedia.org/wiki/OPTICS_algorithm#Extracting_the_clusters
K-means clustering is one of the most popular method of vector quantization, originally from signal processing. Although this method is not density-based, it's included in the library for completeness.
http://en.wikipedia.org/wiki/K-means_clustering
Node:
npm install density-clustering
Browser:
bower install density-clustering
# build
npm install
gulp
var dataset = [
[1,1],[0,1],[1,0],
[10,10],[10,13],[13,13],
[54,54],[55,55],[89,89],[57,55]
];
var clustering = require('density-clustering');
var dbscan = new clustering.DBSCAN();
// parameters: 5 - neighborhood radius, 2 - number of points in neighborhood to form a cluster
var clusters = dbscan.run(dataset, 5, 2);
console.log(clusters, dbscan.noise);
/*
RESULT:
[
[0,1,2],
[3,4,5],
[6,7,9],
[8]
]
NOISE: [ 8 ]
*/
// REGULAR DENSITY
var dataset = [
[1,1],[0,1],[1,0],
[10,10],[10,11],[11,10],
[50,50],[51,50],[50,51],
[100,100]
];
var clustering = require('density-clustering');
var optics = new clustering.OPTICS();
// parameters: 2 - neighborhood radius, 2 - number of points in neighborhood to form a cluster
var clusters = optics.run(dataset, 2, 2);
var plot = optics.getReachabilityPlot();
console.log(clusters, plot);
/*
RESULT:
[
[0,1,2],
[3,4,5],
[6,7,8],
[9]
]
*/
// VARYING DENSITY
var dataset = [
[0,0],[6,0],[-1,0],[0,1],[0,-1],
[45,45],[45.1,45.2],[45.1,45.3],[45.8,45.5],[45.2,45.3],
[50,50],[56,50],[50,52],[50,55],[50,51]
];
var clustering = require('density-clustering');
var optics = new clustering.OPTICS();
// parameters: 6 - neighborhood radius, 2 - number of points in neighborhood to form a cluster
var clusters = optics.run(dataset, 6, 2);
var plot = optics.getReachabilityPlot();
console.log(clusters, plot);
/*
RESULT:
[
[0, 2, 3, 4],
[1],
[5, 6, 7, 9, 8],
[10, 14, 12, 13],
[11]
]
*/
var dataset = [
[1,1],[0,1],[1,0],
[10,10],[10,13],[13,13],
[54,54],[55,55],[89,89],[57,55]
];
var clustering = require('density-clustering');
var kmeans = new clustering.KMEANS();
// parameters: 3 - number of clusters
var clusters = kmeans.run(dataset, 3);
console.log(clusters);
/*
RESULT:
[
[0,1,2,3,4,5],
[6,7,9],
[8]
]
*/
Open folder and run:
mocha -R spec
Software is licensed under MIT license. For more information check LICENSE file.
FAQs
Density Based Clustering in JavaScript
The npm package density-clustering receives a total of 286,995 weekly downloads. As such, density-clustering popularity was classified as popular.
We found that density-clustering demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.