1. Concept of birch Algorithm
Birch (balanced iterative clustering and clustering using hierarchies) is short for balancing iteration conventions and clustering using hierarchical methods. The birch algorithm was proposed by Tian Zhang in 1996. Reference 1. First, Birch is a clustering algorithm. Its biggest feature is that it can use limited memory resources to complete high-quality clustering for large datasets, at the same time, the I/O cost can be minimized through a single-time Data Set scan.
First, let's explain what clustering is. From a statistical point of view, clustering is to give a dataset containing n data points and a distance measurement function f (for example, to calculate the average distance between every two data points in a cluster ), you need to divide the dataset into k clusters (or the number K is not given, and the algorithm automatically finds the optimal number of clusters). The final result is to find an optimal dataset division, minimize the value from the measurement function f. From the perspective of machine learning, clustering is an unsupervised learning algorithm. By clustering a dataset into n clusters, the distance between the interior points of the cluster is minimized, and the distance between clusters is maximized.
Features of the birch algorithm:
(1) Birch tries to use available resources to generate the best clustering results. Given a limited primary storage, an important consideration is to minimize the I/O time.
(2) Birch adopts a multi-stage clustering technology: the single-side scanning of a dataset generates a basic clustering. The additional scanning over one or more times can further improve the clustering quality.
(3) Birch is an incremental clustering method because it makes decisions on clustering for each data point based on the processed data point, rather than the global data point.
(4) If the cluster is not spherical, birch cannot work well because it uses the concept of radius or diameter to control the boundaries of the cluster.
Two concepts are introduced in the birch algorithm: clustering feature and clustering feature tree.
1.1 clustering features (CF)
Cf is the core of the birch incremental clustering algorithm. nodes in the CF tree are composed of CF. a cf is a triple, which represents all the information of the cluster. Given n d-dimensional data points {x1, x2,..., xn}, CF is defined as follows:
Cf = (n, ls, SS)
N is the number of nodes in the subclass, LS is the linear sum of N nodes, and SS is the sum of squares of N nodes.
CF has a feature that allows summation. The specific descriptions are as follows: CF1 = (N1, LS1, SS1), CF2 = (N2, ls2, ss2 ), CF1 + CF2 = (N1 + N2, LS1 + ls2, SS1 + ss2 ).
For example:
Suppose there are three data points in cluster C1: (2, 3), (4, 5), (5, 6), CF1 = {3, (2 + 4 + 5, 3 + 5 + 6 ), (2 ^ 2 + 4 ^ 2 + 5 ^ 2, 3 ^ 2 + 5 ^ 2 + 6 ^ 2) }={ 3, (11,14), (45,70)}, same, CF2 = {4, (100,101), ()} of cluster C2, then the clustering feature cf3 of cluster C3 combined by cluster C1 and cluster C2 is calculated as follows:
Cf3 = {3 + 4, (11 + 40, 14 + 42), (45 + 101, 70 + 145,171) }={ 7 )}
In addition, two concepts are introduced: The Quality Center of the cluster and the radius of the cluster. If a cluster contains N data points: {Xi}, I = 1, 2, 3... N., the formula for center C and radius R is as follows:
C = (X1 + X2 +... + Xn)/n (here X1 + X2 +... + Xn is vector addition)
R = (| X1-C | ^ 2 + | X2-C | ^ 2 +... + | xn-c | ^ 2)/n
The cluster radius indicates the average distance between all vertices in the cluster and the cluster center. Cf stores statistics on the features of all data points in the cluster. Therefore, when we add a data point to a cluster, the detailed features of the data point, such as the attribute value, this feature allows birch clustering to compress datasets to a large extent.
1.2 clustering feature tree (CF tree)
The CF tree structure is similar to a B-tree. It has two parameters: Internal node balancing factor B, leaf node balancing factor L, and cluster radius threshold T. Each node in the tree can contain up to B child nodes, which are marked as (CFI, childi) and 1 <= I <= B. CFI is the I-th clustering feature of the node, childi points to the I child node of the node, which corresponds to the I clustering feature of the node. For example, a CF tree with a height of 3, B of 6, and L of 5:
A CF tree is a compressed representation of a dataset. Each input of a leaf node represents cluster C, which contains several data points and the dense areas of the original dataset, the more data points in cluster C, the more sparse the area, the fewer data points in cluster C, and the radius of cluster C is smaller than or equal to T. With the addition of data points, the CF tree is dynamically built, and the insertion process is a bit similar to the B-tree. The algorithm is shown as follows:
(1) Start from the root node and select the nearest child node from top to bottom (2) after arriving at the leaf node, check whether the latest tuples CFI can absorb this data point. Yes, update the CF value, can you add a new tuple? If you add a new tuple, otherwise, split the farthest pair of tuples as seeds and re-allocate other tuples Based on the closest distance (3) update the CF information of each non-leaf node. If the node is split, insert a new tuple into the parent node and check the split until the root node
There are multiple options for distance functions between computing nodes. Common distance functions include Euclidean distance function and Manhattan distance function. The specific formula is as follows:
During the construction of the CF tree, an important parameter is the cluster radius threshold T, because it determines the size of the CF tree, so that the CF tree can adapt to the current memory size. If t is too small, the number of clusters will be very large, resulting in an increase in the number of Tree nodes, this may cause the memory to be insufficient before all data points are scanned.
2. algorithm flow
Shows the birch algorithm process:
The implementation of the entire algorithm is divided into four stages:
(1) scan all data, establish an initialized CF tree, and divide the dense data into clusters. sparse data is treated as isolated points.
(2) This stage is optional. The global or semi-global clustering algorithms in phase 3 have input range requirements to meet the speed and quality requirements, therefore, this stage builds a smaller CF tree based on phase 1.
(3) remedy the Split Caused by the input order and page size. Use the global/semi-global algorithm to cluster all leaf nodes.
(4) This stage is also optional. Use the center point of phase 3 as the seed to re-allocate the data points to the nearest seed to ensure that the duplicated data is distributed to the same cluster, add cluster labels at the same time
For detailed procedures, see document 1.
3. Algorithm Implementation
The inventor of the birch algorithm completed the implementation of the birch Algorithm in 1996. It was implemented in C ++ and has been compiled and approved under Solaris.
In addition, the implementation of the algorithm can also be referred to: http://blog.sina.com.cn/s/blog_6e85bf420100om1i.html
(Sina Weibo: @ quanliang _ machine learning)
References:
1. Birch: An Efficient Data Clustering Method for very large databases