Socket
Socket
Sign inDemoInstall

@turf/clusters-kmeans

Package Overview
Dependencies
Maintainers
6
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/clusters-kmeans

turf clusters-kmeans module


Version published
Weekly downloads
500K
increased by4.75%
Maintainers
6
Weekly downloads
 
Created

What is @turf/clusters-kmeans?

@turf/clusters-kmeans is a module from the Turf.js library that provides functionality for clustering geographical points using the K-means algorithm. This is particularly useful for spatial analysis and geographic data visualization.

What are @turf/clusters-kmeans's main functionalities?

Basic K-means Clustering

This feature allows you to perform K-means clustering on a set of geographical points. The code sample demonstrates how to cluster six points into two clusters.

const turf = require('@turf/turf');
const points = turf.featureCollection([
  turf.point([0, 0]),
  turf.point([2, 2]),
  turf.point([3, 3]),
  turf.point([8, 8]),
  turf.point([8, 9]),
  turf.point([7, 8])
]);
const clustered = turf.clustersKmeans(points, {numberOfClusters: 2});
console.log(clustered);

Custom Number of Clusters

This feature allows you to specify the number of clusters you want to create. The code sample demonstrates clustering the same six points into three clusters.

const turf = require('@turf/turf');
const points = turf.featureCollection([
  turf.point([0, 0]),
  turf.point([2, 2]),
  turf.point([3, 3]),
  turf.point([8, 8]),
  turf.point([8, 9]),
  turf.point([7, 8])
]);
const clustered = turf.clustersKmeans(points, {numberOfClusters: 3});
console.log(clustered);

Cluster Properties

This feature allows you to retain and inspect the properties of the original points after clustering. The code sample demonstrates how to cluster points and then log the properties of each clustered point.

const turf = require('@turf/turf');
const points = turf.featureCollection([
  turf.point([0, 0], {name: 'A'}),
  turf.point([2, 2], {name: 'B'}),
  turf.point([3, 3], {name: 'C'}),
  turf.point([8, 8], {name: 'D'}),
  turf.point([8, 9], {name: 'E'}),
  turf.point([7, 8], {name: 'F'})
]);
const clustered = turf.clustersKmeans(points, {numberOfClusters: 2});
console.log(clustered.features.map(f => f.properties));

Other packages similar to @turf/clusters-kmeans

Keywords

FAQs

Package last updated on 10 Jul 2021

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc