In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this "python how to achieve dbscan algorithm" article, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "python how to achieve dbscan algorithm" article.
DBSCAN algorithm is a density-based spatial clustering algorithm. The algorithm uses the concept of density-based clustering, that is, the number of objects (points or other spatial objects) contained in a certain area of the clustering space is not less than a given threshold. The remarkable advantage of DBSCAN algorithm is that it has high clustering speed and can effectively deal with noise points and find spatial clustering of arbitrary shape. However, because it operates directly on the whole database and uses a global density parameter when clustering, it also has two obvious weaknesses:
1. When the amount of data increases, a large amount of memory is required to support Imax 0, which consumes a lot of money.
two。 When the density of spatial clustering is uneven and the distance between clusters is very different, the clustering quality is poor.
Clustering process of DBSCAN algorithm
The DBSCAN algorithm is based on the fact that a cluster can be uniquely determined by any of the core objects. The equivalence can be expressed as follows: for any data object p that satisfies the core object condition, the set of all data objects in database D that can reach the density of p constitutes a complete cluster C, and p belongs to C.
General process
First determine the center point according to the given radius r, that is, the number of points contained in the radius r is greater than our requirement (n > = minPionts).
Then traverse all the central points, grouping the mutually accessible central points and the points they include
After the whole group is finished, the point that is not included in any group is the outlier!
Import dependent import numpy as npimport matplotlib.pyplot as pltfrom sklearn import datasets to find the distance between a point and a point (Euclidean distance) def cuircl (pointA,pointB): distance = np.sqrt (np.sum (pointA-pointB,2)) return distance to find temporary clusters, that is, to determine all the central points Non-central point def firstCluster (dataSets,r,include): cluster = [] m = np.shape (dataSets) [0] ungrouped = np.array ([i for i in range (m)]) for i in range (m): tempCluster = [] # first storage center cluster tempCluster.append (I) for j in range (m): if (dataSets [iMagne:], dataSets [jMagee:])
< r and i != j ): tempCluster.append(j) tempCluster = np.mat(np.array(tempCluster)) if (np.size(tempCluster)) >= include: cluster.append (np.array (tempCluster). Flatten ()) # returns List center= [] n = np.shape (cluster) [0] for k in range (n): center.append (cluster [k] [0]) # the other is the non-central point, ungrouped = np.delete (ungrouped,center) # ungrouped is the non-central point return cluster,center,ungrouped
Traverse and aggregate all center points
Def clusterGrouped (tempcluster Centers): M = np.shape (tempcluster) [0] group = [] # whether the corresponding point has been traversed position = np.ones (m) unvisited = [] # untraversed point unvisited.extend (centers) # all points have been traversed for i in range (len (position)): coreNeihbor = [] result = [] # Delete the first # remove your neighbor node This paragraph is similar to depth traversal if position [I]: # fill neighboring nodes into coreNeihbor.extend (list (tempcluster [I] [:])) position [I] = 0 temp = coreNeihbor # traverse all reachable points according to depth # traverse all neighbor nodes while len (coreNeihbor) > 0 : # Select the current point present = coreNeihbor [0] for j in range (len (position)): # if you haven't visited if position [j] = = 1: same = [] # find all the reachable points If (present in tempcluster [j]): cluster = tempcluster [j] .tolist () diff = [] for x in cluster: if x not in temp: # make sure there is no duplicate point diff.append (x) temp.extend (diff) position [j] = 0 # Delete the current point del coreNeihbor [0] result.extend (temp) Group.append (list (set (result) I + = 1 return group
Core algorithm over!
Generate random data of concentric circle type for testing
# generating non-convex data factor represents the distance ratio of the inner and outer circles X _ (Magi) Y1 = datasets.make_circles (n_samples = 1500, factor = .4, noise = .07) # Parameter selection, 0.1 is the radius of the circle, 6 is the number of points required to determine the center point Generate the classification result tempcluster,center,ungrouped = firstCluster (Xmai 0.1 Magi 6) group = clusterGrouped (tempcluster Center) # the following is further processing of the data after classification num = len (group) voice = list (ungrouped) Y = [] for i in range (num): Y.append (X [group [I]) flat = [] for i in range (num): flat.extend (group [I]) diff = [x for x in voice if x not in flat] Y.append (X [diff]) Y = np.mat (np.array (Y))
Drawing ~
Color = ['red','blue','green','black','pink','orange'] for i in range (num): plt.scatter (Y [0memi] [:, 0], Y [0memi] [:, 1], c = color[ I]) plt.scatter (Y [0mai] 1] [:, 0], Y [0Magne1] [:, 1] C = 'purple') plt.show () these are the contents of the article on "how python implements the dbscan algorithm" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.