DBSCAN is a density based clustering algorithm that works by successively growing a cluster from initial seed points . If the density in the circle proximity (which has the radius parameter Eps) of a point is above or equal a threshold level, denoted by the MinPts parameter, the cluster is expanded forward by assigning all the unassigned points in the neighborhood to it. The algorithm then recursively proceeds with the same steps for each of the newly added points to the cluster. Points that will not be assigned to any cluster by the end of this process are labeled as noise.
The current implementation supports only two dimensional data.
The algorithm also works on data points given by GPS coordinates. Moreover, the algorithm can be used on data with a time dimension also. This allows for spatio-temporal clustering.
Import the script.
Sample Data Format
Basic 2D Data
var point_data =x: 01y: 5x: 2y: 4x: 0y: 7;
var gps_point_data =location:accuracy: 30latitude: 557858667longitude: 125233995location:accuracy: 10latitude: 454238667longitude: 125233995location:accuracy: 5latitude: 253438667longitude: 116533995;
Where accuracy is given in meters.
Spatial and Temporal Data
var time_gps_data =location:accuracy: 30latitude: 557858667longitude: 125233995timestamp: 1349958445location:accuracy: 10latitude: 454238667longitude: 125233995timestamp: 123958445location:accuracy: 5latitude: 253438667longitude: 116533995timestamp: 1350958445;
var time_point_data =x: 01y: 5timestamp: 1350958445x: 2y: 4timestamp: 123958445x: 0y: 7timestamp: 1349958445;
Where timestamp is given by the UNIX timestamp in seconds for the sample point.
- Run the algorithm. To run the algorithm you need to provide the data along with the eps and minPts parameters. For the traditional DBSCAN the steps are the following:
// Configure a DBSCAN instance.var dbscanner = datapoint_data;
The distance functions available are: 'EUCLIDEAN', 'HAVERSINE' (for GPS data), 'MANHATTAN'.
Additionally you can provide your own distance function, which must accept at least two parameters (the two points), and passing it to the distance method. The next step is to simply run the clustering algorithm.
// This will return the assignment of each point to a cluster number,// points which have -1 as assigned cluster number are noise.var point_assignment_result = ;// (OPTIONAL) If you need the cluster centers for each of the// identified clusters use thisvar cluster_centers = dbscanner; `
In case of spatio-temporal data, as described above, additional parameters must be supplied. Such as time_eps (difference in seconds used as the time equivalent of the distance eps value).
var dbscanner = datadata;
The default time distance function is given by the absolute difference between timestamps. Other functions can be used by passing a function to the time_distance method, it also should accept two objects with a timestamp field.
var dbscanner = datadata;
The remaining steps are similar.
See example.html, use the console to view the raw input data and raw output.