matlab cluster analysis [GO]
MATLAB provides a series of functions for clustering analysis, summed up the specific methods are as follows:
Method One: Direct clustering, using Clusterdata function to cluster the sample data, its disadvantage is that the user can choose a narrow face, can not change the distance calculation method, the method users do not need to understand the principle and process of clustering, but the clustering effect is limited.
Method Two: Hierarchical clustering, the method is more flexible, need to carry out detailed understanding of the clustering principle, the following process needs to be processed: (1) Find the similarity and non-similarity between the variables 22 in the data set, and use the Pdist function to calculate the distance between variables; (2) Define the connection between variables with the linkage function ; (3) The Cophenetic function is used to evaluate the clustering information, and (4) to create the cluster with the cluster function.
Method Three: Dividing clustering, including K-means clustering and K-centric clustering, also requires a series of steps to complete the process, requiring users to have a clearer understanding of the principle and process of clustering.
Next, the related functions and related clustering methods in MATLAB are introduced.
1 . Introduction to the related functions in MATLAB
1.1 Pdist function
Call format: Y=pdist (X, ' metric ')
Description: Calculates the distance between objects in the X data matrix using the method specified by ' metric '. ’
X: A matrix of MXN, which is a dataset of M objects, each of which has a size of N.
Metric ' values are as follows:
' Euclidean ': Euclidean distance (default); ' Seuclidean ': standardized Euclidean distance;
' Mahalanobis ': Markov distance; ' Cityblock ': Braddock distance;
' Minkowski ': Minkowski distance; ' cosine ':
' Correlation ': ' Hamming ':
' Jaccard ': ' Chebychev ': Chebychev distance.
1.2 Squareform function
Call format: Z=squareform (Y,..)
Description: The distance matrix is forced to convert from the upper triangular form to a square form, or from a phalanx form to the upper triangular form.
1.3 Linkage function
Call format: Z=linkage (Y, ' method ')
Description: Use the algorithm specified by the ' method ' parameter to compute the cluster tree.
The distance vector returned by the y:pdist function;
Method: The following values are desirable:
' Single ': Shortest distance method (default); ' Complete ': longest distance method;
' Average ': non-weighted mean distance method; ' Weighted ': Weighted average method;
' centroid ': centroid distance method; ' Median ': weighted centroid distance method;
' Ward ': Inner square Distance method (minimum variance algorithm)
Returns: Z is a matrix that contains the cluster tree information (m-1) x3.
1.4 Dendrogram function
Call format: [H,t, ...] =dendrogram (z,p, ...)
Description: Generates an icicle Chart (pedigree chart) with only the top p nodes.
1.5 cophenet function
Call format: c=cophenetic (z,y)
Description: Calculates the cophenet correlation coefficients using the z calculation generated by the Y and linkage functions generated by the Pdist function.
1.6 Cluster function
Call format: T=cluster (Z,...)
Description: Creates a classification based on the output Z of the linkage function.
1.7 Clusterdata function
Call format: T=clusterdata (X,...)
Description: Creates a classification based on data.
T=clusterdata (X,cutoff) is equivalent to the following set of commands:
Y=pdist (X, ' Euclid ');
Z=linkage (Y, ' single ');
T=cluster (Z,cutoff);
2. the design of matlab Clustering program
2.1 Method One: One- time clustering method
x=[11978 12.5 93.5 31908;..; 57500 67.6 238.0 15900];
T=clusterdata (x,0.9)
2.2 Method Two and method three design flow: Step Up Clustering
STEP1 finding similarity between variables
Using Pdist function to calculate the similarity matrix, there are many ways to calculate the distance, it is best to standardize the data with Zscore function before calculating.
X2=zscore (X); % Standardized data
Y2=pdist (X2); % calculated distance
Step2 defining a connection between variables
Z2=linkage (Y2);
STEP3 Evaluation of Cluster information
C2=cophenet (Z2,Y2); 0.94698
STEP4 create clusters, and make genealogy maps
T=cluster (z2,6);
H=dendrogram (Z2);
MATLAB cluster analysis [GO]