4

I am using the dbscan cluster (package fpc) in R to find clusters on a set of latitudes/longitudes coordinates. I want to find an eps distance that corresponds to a meaningful geographic distance (e.g., a mile or kilometer)

My data looks like this:

  Longitude Latitude
1 -87.53163 41.68640
2 -87.59986 41.67341
3 -87.80099 41.95469
4 -87.82481 41.97409
5 -87.67671 41.68832
6 -87.67751 41.73192

Through trial and error, I got a set of clusters that look plausible. In the attached map.

dbscan.clust1 <- dbscan(points, eps=.025, MinPts=20)

What I'd like to do, is find the eps distance that would correspond to a meaningful measurement (i.e., 1 mile = .025 eps)

enter image description here

  • Can you possibly include a reproducible example? As for general distance calculations when working with EPSG:4326, I would recommend geodist from the gmt package. – fdetsch May 11 '15 at 9:02
5

The ELKI version of DBSCAN has full support for geodetic distances.

Just set the distance function to LatLngDistanceFunction or LngLatDistanceFunction (depending on your data format), and specify your epsilon radius in meters.

ELKI also has R*-tree index acceleration, making this type of clustering very fast. Benchmark it against R, and you will see R lose by several orders of magnitude.

The R fpc::dbscan version of DBSCAN is very very bad. Don't use it.

If you insist on a R solution (and don't care about performance),
see the documentation of fpc::dbscan:

  method: "dist" treats data as distance matrix (relatively fast but
          memory expensive), "raw" treats data as raw data and avoids
          calculating a distance matrix (saves memory but may be slow),
          "hybrid" expects also raw data, but calculates partial
          distance matrices (very fast with moderate memory
          requirements).

I don't think fpc::dbscan allows you to specify a distance function, but you can precompute a distance matrix and use it. This has the drawback of needing O(n²) memory, so it won't scale to large data sets, but it will work for tiny data sets only anyway.

  • Thanks, I will look into ELKI. My confusion with various implementations (e.g. fpc, and sklearn) has been the black box of eps. I've been trying to implement my own function by it's not going well. stackoverflow.com/questions/30578298/… – mech Jun 4 '15 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.