Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the implementation of DBSCAN algorithm in r language

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

R language DBSCAN algorithm is how to achieve, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

DBSCAN (Density-BasedSpatial Clustering of Applications with Noise), a density-based clustering method, that is, to find dense regions separated by low-density regions, requires that the number of objects (points or other spatial objects) contained in a certain region in the clustering space is not less than a given threshold.

One or two parameters.

1, distance parameter (Eps)

2, the minimum number of points in the neighborhood (MinPts)

Second, the points are classified according to the density based on the center.

The center-based approach to density divides points into three categories:

1, the core. A point inside a dense area. The number of points in the area with the radius of Eps is not less than MinPts (including itself).

2, boundary point. A point on the edge of a dense area, not a core point, but in the neighborhood of one or more core points.

3, noise point. A point in a sparse region is neither a core point nor a boundary point.

4, the density can reach. If the point p is in the Eps neighborhood of the core point Q, then p is said to be directly densely reachable from Q. If there is a dot chain p1Det p2, … Pn,p1=q,pn=p,pi+1 is directly accessible from pi, then the call point p is accessible from Q with respect to r and M density, and the density reachability is unidirectional.

Algorithm flow

Starting from a certain point, the points with reachable density are grouped together, and the area is expanded continuously until all the points are visited.

R language realization

To implement DBSCAN clustering in R, you can use the dbscan () function in the fpc package. In the following example, we demonstrate using the dataset multishapes in the factoextra package.

You can view the clustering results as follows:

The classification results of each sample point can be viewed with db$cluster, where 0 represents the noise point. The classification results of 50 points are randomly displayed as follows:

Select the optimal EPS value

The method is to calculate the average distance from each point to its nearest neighbor k points. The value of k is specified by the user according to MinPts. In the R language, the kNNdistplot () function in the dbscan package is used for calculation.

It can be seen from the figure that the inflection point is about 0.15, so it can be considered that the optimal Eps value is about 0.15.

Custom distance formula

The distance formula in dbscan () function is Euclidean distance, which can not be used in some specific situations. For example, to calculate the distance between two points on a map, it is necessary to apply a specific formula to calculate the distance between two points on the map.

Many of the functions in R are open source, so you can see the original program of this function by running fpc::dbscan directly. We use the distm () function in the geosphere package to modify the distance calculation formula in the original program to realize the calculation of the distance between two points on the map.

Change the distcomb function in the original program to the following form:

Rename the modified dbscan function to disdbscan, and re-cluster the data:

Advantages and disadvantages of DBSCAN

Advantages:

The main results are as follows: (1) the clustering speed is fast and can effectively deal with noise points.

(2) Spatial clustering of arbitrary shape can be found.

(3) the clustering results almost do not depend on the traversal order of points.

(4) there is no need to enter the number of clusters to be divided.

Disadvantages:

(1) when the amount of data increases, a large amount of memory is required to support Icano, and the consumption is also very high.

(2) when the density of spatial clustering is uneven and the difference between clusters is very different, the clustering quality is poor.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report