Original link:tecdat.cn/?p=20960

Original source:Tuo End number according to the tribe public number

To illustrate the hierarchical clustering technique and the K-means, I used the urban temperature data set, which includes monthly mean temperatures for several cities.

We have 15 cities and we do monthly observations

Boxplot (temp[,1:12],main=" temp ")Copy the code

Since the variance looks pretty stable, we’re not going to “normalize” the variables here,

> apply(month,2,sd)Copy the code

To get a hierarchical cluster analysis, use examples

 hclust(dist , method = "ward")
 
Copy the code

Another option is to use

 
> plot(h2)
Copy the code

Here, we visualize the observations using principal component analysis. We also have a number of auto-selected classes here, which is 3. We can get a description of the group

Or directly

 cutree(cah,3)
Copy the code

We can also visualize these classes ourselves,

 PCA(X,scale.unit=FALSE)
 plot(  ind$coord[,1:2],col="white")
 text( ind$coord[,1],acp$ind$coord[,2],
 
Copy the code

The centers of these clusters can be plotted

 > points(PT$Dim.1,PT$Dim.2,pch=19)
Copy the code

If we add Voronoi sets around these centers, what we see is the middle point, which happens to be the intersection of the three regions

vormo(PT$Dim.1,PT$Dim.2)
plot(V,add=TRUE)
Copy the code

To visualize these regions, use a Voronoi diagram, also known as a Tyson polygon or Dirichlet diagram, which consists of a set of continuous polygons consisting of vertical bismuters connecting two adjacent lines.

P = function (x, y) {+ which. Min (1 - x (PT $Dim.) ^ 2 + (PT $Dim. 2 - y) ^ 2) image (vx, vy, z, col = c (RGB (1, 0, 2),Copy the code

In fact, these three groups (and these three regions) are also the ones we got using the K-mean algorithm,

kmeans(coord[,1:2],3)

K-means clustering 
with 3 clusters of sizes 3, 7, 5
Copy the code

Since we have some spatial data, we can visualize it on a map

points(Long,Lati,col=groups.3)
Copy the code

Or, to visualize these areas, use

 for(i in 1:3) 
+ Ellipse( Long[groups.3==i],
Copy the code


Most welcome insight

1.R language K-Shape algorithm stock price time series clustering

2. Comparison of different types of clustering methods in R language

3. K-medoids clustering modeling and GAM regression are performed for time series data of electricity load using R language

4. Hierarchical clustering of IRIS data set of R. language

5.Python Monte Carlo K-means clustering

6. Use R to conduct website comment text mining clustering

7. Python for NLP: Multi-label text LSTM neural network using Keras

8.R language for MNIST data set analysis and exploration of handwritten digital classification data

9.R language deep learning image classification based on Keras small data sets