{"id":163,"date":"2026-11-13T12:33:13","date_gmt":"2026-11-13T04:33:13","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-dbscan-grows-a-density-cluster\/"},"modified":"2026-11-13T21:51:37","modified_gmt":"2026-11-13T13:51:37","slug":"how-dbscan-grows-a-density-cluster","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-dbscan-grows-a-density-cluster\/","title":{"rendered":"How DBSCAN grows a density cluster"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>DBSCAN<\/strong> grows clusters from core points. A core point has at least minPts points, including itself, inside radius \u03b5. A cluster is a core point plus every point density-reachable from it through a chain of cores. Points that are within \u03b5 of a cluster and are not themselves cores are border points. Everything else is noise. The algorithm needs no preset number of clusters. With a spatial index a run is about <strong>O(n log n)<\/strong>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">k-means wants blobs around means and wants k. DBSCAN wants regions where points are packed at least minPts deep inside every ball of radius \u03b5, and it wants the noise points left unlabeled. The reachability definition prevents a sparse bridge of non-core points from gluing two dense regions together, because a border point does not extend the cluster further.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The parameters \u03b5 and minPts are the model. A too-large \u03b5 merges clusters. A too-small \u03b5 labels everything as noise. minPts is often set near twice the dimension or a little higher, and \u03b5 is chosen from a k-distance plot. Neither choice is free of the data.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">The partition into clusters, border points, and noise is defined by \u03b5 and minPts, and a standard implementation computes it in one pass over the cores. Border points that are reachable from two clusters are assigned to whichever cluster is expanded first, so that detail of the labeling depends on order. The cores&#8217; cluster membership does not. Time is O(n\u00b2) with a linear neighbor search and about O(n log n) with a range tree or a grid when the data allow it.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The algorithm uses a symmetric distance. A density that varies across the set, clusters inside clusters at different scales, defeats a single \u03b5. OPTICS and HDBSCAN are the relatives that address variable density. DBSCAN does not place a center and does not minimize a squared-error objective.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>For each point, find the neighbors inside radius \u03b5. Mark the point as core if the neighbor count is at least minPts.<\/li>\n<li>Visit each unvisited core. Start a cluster and expand a queue through every core neighbor, adding the density-reachable cores and their neighbor points.<\/li>\n<li>A non-core neighbor is a border point of this cluster and is not used to expand further.<\/li>\n<li>Points never reached are noise.<\/li>\n<li>Choose \u03b5 from the data, often by inspecting the distance to the minPts-th neighbor, rather than by guessing a coordinate unit.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">A single global \u03b5 assumes one density scale. k-means assumes blobs and a known k. DBSCAN assumes neither, and it assumes the distance and \u03b5 match the scale of the clusters the caller cares about. Border-point assignment can depend on expansion order. Core membership does not.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when a border point is allowed to recruit new members<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Expand the cluster through every neighbor, core or not<\/td>\n<td>A chain of border points can connect two dense regions the definition keeps separate. Only cores expand the cluster.<\/td>\n<\/tr>\n<tr>\n<td>Set \u03b5 once for a data set whose clusters have different scales<\/td>\n<td>One radius cannot be inside the tight cluster and inside the loose cluster at the same time. The single-\u03b5 definition will merge, split, or mark noise.<\/td>\n<\/tr>\n<tr>\n<td>Replace the neighbor count by a k-means objective<\/td>\n<td>The algorithms optimize different criteria. A low squared error is not a DBSCAN cluster.<\/td>\n<\/tr>\n<tr>\n<td>Forget the spatial index and quote O(n log n)<\/td>\n<td>The log factor comes from the neighbor search. A linear scan of all points for each query is quadratic.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A preset number of spherical clusters is k-means. A hierarchy of densities is OPTICS or HDBSCAN. DBSCAN is the single-\u03b5 density clustering with core and border points.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment marks a point as a core when at least minPts points, counting itself, lie inside \u03b5, and only cores expand a cluster. With \u03b5 = 1.5 and minPts = 2, the pairs (0, 0),(1, 0) and (5, 5),(6, 5) are two clusters and (10, 0) is noise. It prints <code>2<\/code>.<\/p>\n\n<pre><code class=\"language-python\">import math\npts = [(0, 0), (1, 0), (5, 5), (6, 5), (10, 0)]\neps, min_pts = 1.5, 2\n\ndef neighbors(i):\n    return [j for j, q in enumerate(pts) if math.hypot(pts[i][0] - q[0], pts[i][1] - q[1]) &lt;= eps]\n\nlabels = [-1] * len(pts)\ncluster = 0\nfor i in range(len(pts)):\n    if labels[i] != -1:\n        continue\n    nbrs = neighbors(i)\n    if len(nbrs) &lt; min_pts:\n        continue\n    labels[i] = cluster\n    stack = nbrs[:]\n    while stack:\n        j = stack.pop()\n        if labels[j] == -1:\n            labels[j] = cluster\n            more = neighbors(j)\n            if len(more) &gt;= min_pts:\n                stack.extend(more)\n        elif labels[j] &lt; 0:\n            labels[j] = cluster\n    cluster += 1\nassert cluster == 2 and labels[-1] == -1\nprint(cluster)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\"><strong>scikit-learn<\/strong>&#8216;s <code>DBSCAN<\/code> groups GPS points and other spatial samples by density and leaves outliers unlabeled. Customer locations and anomaly clumps are the usual input. K-means forces every point into a cluster and asks for the number of clusters first.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop a single \u03b5 when the clusters visibly live at several densities. Use a hierarchical density method. Keep DBSCAN when one density scale, a distance, and an explicit noise label match the data.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for DBSCAN returns the core-point rule and the reason border points do not expand a cluster. <strong>DBSCAN forms a cluster by expanding through core points that have at least minPts neighbors inside radius \u03b5, and it leaves the remaining points as border or noise.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: DBSCAN grows clusters from core points. A core point has at least minPts points, including itself, inside radius \u03b5. A cluster is a core point plus every point density-reachable from it through a chain of cores. Points that are within \u03b5 of a cluster and are not&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,48],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-clustering"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":562,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/163\/revisions\/562"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}