DBSCAN and HDBSCAN
Find regions by how densely points gather, without deciding the number of clusters in advance.
When you plot wildlife GPS tracking records on a map, location points crowd together in some areas and appear only sparsely in others. Researchers want to use these records to find the activity areas where the animals often stay.
But there is no guarantee that activity areas are gathered in circles; they may stretch out along mountain ranges or valleys. A few isolated observations may also be locations recorded while the animals were on the move.
DBSCAN and HDBSCAN are the best-known methods that treat areas where points are dense as clusters and separate out low-density locations like these. Neither requires you to specify the number of clusters in advance, and both are useful for finding irregularly shaped clusters that K-means does not capture well. However, they differ in how they define density and in their ability to handle varying densities.
In this article we look at how the two algorithms work and their main settings, a GPS analysis example, interpreting noise and cluster stability, the limits of the silhouette score, and what to watch for in real research.
What is density-based clustering?
Density-based clustering defines clusters as areas where observations are gathered closely enough together.
Dense areas separated from other clusters are each classified as separate clusters, and observations without enough neighbors around them can be marked as noise. Here, noise does not mean bad data. It means the point did not belong to any cluster under the chosen density criterion.
For example, if wildlife stayed around a feeding area for a long time, many GPS coordinates may be recorded within a small range. Conversely, coordinates recorded while moving between feeding areas appear relatively sparsely. Density-based algorithms can be used to distinguish situations like these, where the distribution of points in space differs.
However, you cannot conclude that a location is a preferred habitat just because it has many GPS locations. The recording interval of the tracking device, the observation time for each animal, and movement speed also affect the density of points.
How is it different from K-means?
K-means first sets the number of clusters K and assigns each observation to the nearest centroid.
So it is generally suited to finding clusters grouped around a center, and it assigns every observation to some cluster.
DBSCAN and HDBSCAN, by contrast, define clusters based on the density of areas where points gather. They can find activity areas that follow a winding valley, and even small dense areas separated from their surroundings. They can also mark points outside clusters as noise.
| Item compared | K-Means | DBSCAN | HDBSCAN |
|---|---|---|---|
| Number of clusters specified in advance | Required | Not required | Not required |
| Cluster shape | Center-based; better for relatively simple shapes | Irregular shapes possible | Irregular shapes possible |
| Density differences | Not modeled directly | Sensitive to a single distance threshold | Examines several density levels hierarchically |
| Noise labeling | None by default | Possible | Possible |
| Main settings | n_clusters | eps, min_samples | min_cluster_size, min_samples |
HDBSCAN is not always better. If the density structure of the data is fairly uniform and the distance criterion is easy to explain, DBSCAN may be enough.
Real-world case: GPS tracking records of wildlife in a mountain region
Suppose an ecology research team attached GPS trackers to 20 wild animals in a mountain region and recorded their locations for 8 weeks.
After data quality checks, 2,400 valid coordinates, resampled to a regular time interval, were used in the analysis. The researchers want to identify spatial activity areas that the animals use repeatedly.
| Item | Example setting |
|---|---|
| Unit of observation | GPS locations recorded at regular time intervals |
| Number of data points | 2,400 coordinates |
| Number of animals | 20 |
| Period | 8 weeks |
| Analysis variables | East–west and north–south coordinates (projected in meters) |
| Purpose of analysis | Identify the main dense areas and relatively sparse locations |
In this example, a cluster is a set of spatial locations where GPS coordinates are dense, not a type of animal. Also, one animal can move across several clusters. To analyze the behavior of a particular animal, you would need to also consider the time order and the animal ID.
How does DBSCAN work?
DBSCAN stands for Density-Based Spatial Clustering of Applications with Noise, and it finds dense areas based on whether there are enough neighbors within a certain distance.
The key settings are eps and min_samples. eps is the maximum distance at which another observation counts as a neighbor. min_samples is the number of neighbors required for a point to count as a core point, and in common implementations it is counted including the point itself.
Core points that are connected within reachable range form the same cluster, and observations that are near a core point but are not core points themselves become border points.
| Point type | Meaning |
|---|---|
| Core point | A point with at least min_samples observations within eps |
| Border point | A point that is not a core point but falls within a core point's neighborhood |
| Noise | A point not assigned to any cluster |
For example, with eps=150m and min_samples=8, you check whether there are at least 8 coordinates, including the point itself, within a 150m radius of a GPS location. Clusters are formed from the connections among core points that meet this condition.
How do you choose DBSCAN's main settings?
If eps is too small, even activity areas that are actually connected can be split into several clusters, and noise can increase.
Conversely, if it is too large, separate activity areas can merge into a single cluster. As min_samples grows, the standard for counting as a core point becomes stricter, making it harder for small dense areas to remain as clusters.
Because this is a distance-based analysis, the coordinate system also matters. If you compute Euclidean distances directly on latitude and longitude, you may wrongly treat degrees as if they were meters. Convert to a projected coordinate system suited to the region, or use a distance suited to latitude–longitude data, such as the great-circle (haversine) distance.
As an aid for choosing eps, you can use a k-nearest-neighbor distance plot. It sorts the distance from each point to its k-th nearest neighbor and looks at where the distance starts to rise sharply.
However, the bend in the plot is not always clear, and it should not be applied mechanically. It is good to also review cluster stability and ecological interpretability across several settings.
How do you read DBSCAN results?
Suppose we applied DBSCAN to the 2,400 GPS coordinates.
| Class | Number of coordinates | Share |
|---|---|---|
| Cluster A | 820 | 34.2% |
| Cluster B | 610 | 25.4% |
| Cluster C | 490 | 20.4% |
| Noise | 480 | 20.0% |
| Total | 2,400 | 100.0% |
In this result, three dense areas were identified, and 20% of all coordinates were not assigned to a cluster under the chosen density criterion. Cluster A contains the most coordinates, but this cannot be interpreted directly as the largest habitat or the most preferred area, because the longer an animal stays in one place, the more coordinates may be recorded there.
Additionally checking the size and shape of the clusters, how often each animal uses them, and visit patterns by time of day can give the spatial results more practical meaning.
How is HDBSCAN different?
HDBSCAN is a hierarchical approach that extends DBSCAN across multiple density levels.
Instead of finding all clusters based on a single fixed eps value, it looks at the cluster structure that forms as density changes and selects relatively stable clusters.
For example, if there is a feeding area where GPS coordinates are very dense alongside a resting area where they are more loosely spread, DBSCAN with a single distance threshold may have trouble finding both areas properly at the same time. HDBSCAN can have an advantage for data with density differences like these.
However, HDBSCAN is also affected by the definition of distance, the density of the sample, and the minimum cluster size. And because the results can change depending on which clusters are selected from the hierarchy, you should check their stability.
What are HDBSCAN's key settings?
min_cluster_size is the main setting that controls the minimum size required to keep a group as a cluster.
If the value is small, even small dense areas can remain as clusters, but if it is large, small areas can be absorbed into larger clusters or become noise.
min_samples controls how strictly local density is judged. In general, larger values find clusters more conservatively and can increase noise. Some implementations set it equal to min_cluster_size when it is not specified, so if you want to compare the effects of the two settings, it is good to specify it explicitly.
| Setting | Main role | If set too large |
|---|---|---|
| min_cluster_size | Minimum size of clusters to keep | Small activity areas may disappear |
| min_samples | How conservatively local density is judged | Noise may increase and clusters may decrease |
| Distance metric | Defines similarity between points | A completely different structure can emerge depending on the metric |
Some implementations let you choose eom or leaf for cluster_selection_method. eom is the default approach that selects relatively stable clusters, while leaf can provide finer clusters from the hierarchy.
How do you interpret HDBSCAN results?
Suppose we applied HDBSCAN to the same coordinates.
Because the algorithm and settings change, the results can differ from DBSCAN.
| Class | Number of coordinates | Share |
|---|---|---|
| Cluster 1 | 780 | 32.5% |
| Cluster 2 | 600 | 25.0% |
| Cluster 3 | 420 | 17.5% |
| Cluster 4 | 300 | 12.5% |
| Noise | 300 | 12.5% |
| Total | 2,400 | 100.0% |
In this example, four clusters and 300 noise coordinates appeared. There is one more cluster than with DBSCAN and the noise rate is lower, but that alone does not mean the HDBSCAN result is more accurate. You need to check the actual locations and connection patterns of each algorithm's clusters, sensitivity to parameters, and so on.
Depending on the implementation, HDBSCAN can provide information on cluster membership strength and cluster stability. Coordinates with low membership strength may be on the edge of a cluster or be observations whose membership is relatively uncertain. However, these scores should not be interpreted directly as the probability that the animals prefer that space.
How do you evaluate cluster quality?
In density-based clustering, it is hard to determine cluster quality with a single score.
The silhouette score can evaluate cohesion within clusters and separation from other clusters, but it can be unfavorable or misleading for irregularly shaped clusters or data with a lot of noise.
So check not only the number of clusters but also their shape and connectivity in space, the noise rate, and whether the clusters hold up when the settings are changed slightly. You can also refer to measures designed to evaluate density-based clusters, such as DBCV (Density-Based Clustering Validation).
| Evaluation perspective | What to check |
|---|---|
| Cluster separation | Are different activity areas spatially distinct? |
| Cluster stability | Does the core structure hold when the settings and sample change slightly? |
| Noise rate | Can you explain why many coordinates were excluded? |
| Ecological meaning | Does it match terrain, food sources, observation times, and so on? |
| Repeated-measures structure | Are the results not dominated by particular animals or recording periods? |
If you are actually studying activity areas, a sensitivity analysis that looks at how much the clusters change after excluding some animals or particular dates is also useful.
Which should you choose, DBSCAN or HDBSCAN?
If the density of the dense areas is fairly uniform and you can clearly explain the distance criterion of interest, DBSCAN is a good starting point.
For example, if the goal of the analysis is to find areas where enough observations gather within a 150m radius of a location, DBSCAN's settings and results are easy to explain intuitively.
On the other hand, if very dense and loosely dense areas are mixed together and it is hard to get suitable results with a single eps, you can consider HDBSCAN. It is also useful especially when you want to look at the hierarchical structure and relative stability of the clusters.
Whichever method you use, it is important to decide on the distance metric and observation interval before the analysis and to check that the results don't change much across different settings. The appropriate method can also depend on whether the goal of the analysis is to distinguish the animals' behavioral states or to explore spatial areas where they stay.
Cautions in the analysis
Don't treat noise as data errors.
Coordinates marked as noise may be places the animals actually traveled through. Before deleting them automatically, distinguish recording errors from normal movement records.
Compute distances between coordinates correctly.
Applying simple Euclidean distance to latitude and longitude can cause distortions that depend on the region and latitude. Compute distances with appropriate projected coordinates or a great-circle distance.
Don't confuse observation density with actual intensity of use.
If animals with a shorter recording interval contribute more coordinates, their activity areas can be overemphasized. Consider the same sampling rule or weights for each animal.
Don't rank cluster numbers.
Names like cluster 0 or cluster 1 are just identifiers assigned by the algorithm and do not indicate priority or size order. The numbers can also change in a different run of the analysis.
Keep in mind the limitation of losing time information.
Ordinary spatial clustering does not reflect the time order of the coordinates. The same location can be used differently depending on the season or time of day, so add a spatiotemporal analysis if needed.
How do you report the results?
When reporting the results of density-based clustering, it is good to state the data collection method, distance metric, coordinate preprocessing, algorithm used, main parameters, number of clusters, noise rate, sensitivity to settings, and so on.
For GPS data in particular, you need to explain the projected coordinate system or distance calculation method and the recording interval so that the results can be reproduced.
Example report
To explore the spatial activity areas of wildlife in a mountain region, DBSCAN and HDBSCAN were applied to 2,400 GPS coordinates collected from 20 animals. The location coordinates were converted to a projected coordinate system in meters so that distances could be computed, and observations resampled to a regular time interval were used.
The DBSCAN analysis identified three dense areas and classified 480 coordinates (20.0%) as noise. HDBSCAN identified four clusters, with 300 noise coordinates (12.5%). These differences can be interpreted as resulting from the way the two algorithms handle density structure and from differences in their main settings. However, noise coordinates cannot be assumed to be erroneous observations, and the ecological meaning of the clusters should be evaluated by also considering each animal's usage patterns and terrain information.
In real research, you should add the parameters used and the results of sensitivity analyses.
Clusters are found by density, not by centers
DBSCAN and HDBSCAN are density-based algorithms that find clusters based on areas where observations gather.
The two methods have in common that they don't require you to specify the number of clusters in advance, they find irregularly shaped clusters, and they can separate out observations that don't belong to any dense area as noise.
DBSCAN defines clusters using a single distance threshold and a minimum number of neighbors. HDBSCAN examines several density levels hierarchically, so it can have an advantage for data that mix areas of different densities. But both methods are affected by the distance metric, the sampling method, and the parameter settings.
The key is not finding more clusters or reducing noise, but reliably separating and interpreting the dense structure the data actually have, in a way that fits the purpose of the analysis.