# dbscan_gps

1.0.1 • Public • Published

# dbscan_gps

A node.js packpage for clustering GPS coordinates by using DBSCAN algorithm.

## Background

DBSCAN (https://en.wikipedia.org/wiki/DBSCAN), per its name suggested, is a density-based clustering algorithm. This module is developped specifically to cluster points with GPS coordinates (in decimal degree format for now) by using the algorithm. You can also modify the module to leverage your own distance function.

Through work, I have also used K-mean, G-means(described in https://github.com/haifengl/smile/), Hierarchical-clustering algorithms. I found that for small dataset of GPS coordinates, they do not work very well.

## Pros and Cons

### Pros

DBSCAN is a very simple yet effective algorithm to cluster data. You can see in the source code the implementation is less than 250 lines. It is also very versatile in clustering different types of data (assuming you can provide custom distance function).

### Cons

The algorithm has a worst complexity of O(n^2) and an average of O(nlogn) complexity. This means if you have a large set of data, the algorithm could become slow. Another con is the fact that you have to specify the minimal number of points in a cluster as well as the epsilon (radius).

## Example

### After clustering

In total, there are 4 clusters predicted

These points are extracted from an individual's Facebook check-ins. Some of the points are discarded as noise points. For example, the one in Hawaii or the few ones in Africa.

In this particular example, we are interested in limiting the radius to 100 Miles radius (you can also use "km" to specify that you are interested in kilometers) and 2 minimal points to form a cluster.

## API

var clustering = new Clustering(dataset, eps, eps_unit, minpts);

@param {array} dataset: an array of points, each point is shaped as [lat, lon]; The lat and lon must be in Decimal Degrees (DD) format

@param {integer} eps: epsilon, the radius of the cluster

@param {string} eps_unit: in either kilometers "km" or miles "mi"

@param {integer} minPts: the minimal number of points in a cluster

clustering.fit(function(e, clusters){ }

@callback {function} callback: (error, clusters): error is an error description in string type,
clusters is an array of clusters; each cluster is another array of points with index coorresponding to the index in the input dataset

## Future Improvement

1. Add parameter to allow custom distance function
2. Add support for other formats of GPS coordinates such as Degrees and decimal minutes (DMM) and Degrees, minutes, and seconds (DMS)

## Package Sidebar

### Install

`npm i dbscan_gps`

### Repository

github.com/ichenjia/dbscan_gps

223

1.0.1

ISC