type
Post
Created date
Jun 16, 2022 01:21 PM
category
Data Science
tags
Machine Learning
Machine Learning
status
Published
Language
From
summary
slug
password
Author
Priority
Featured
Featured
Cover
Origin
Type
URL
Youtube
Youtube
icon
Definition
- Divide the data objects into a set of NESTED clusters organised as a hierarchical tree
- The number of clusters is chosen a priori.
- Visualised as a dendrogram
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F994df7e9-e961-43f5-a190-edb4957d5308%2FUntitled.png%3Ftable%3Dblock%26id%3D410e6800-4708-44c3-83d8-0f1e542b51b7%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DrKBSN-GmkxxmqstVdwATnWRxCsFkyy-uB0BPsoJQGAg?table=block&id=410e6800-4708-44c3-83d8-0f1e542b51b7&cache=v2)
Theory
There are 2 types of Hierarchical Clustering (i.e., Agglomerative & Divisive)
- Agglomerative:
- At start, every observation is a cluster. Merge the most similar clusters step by step until all observations are in one cluster.
- Single Linkage (where finding the
minimal
clusters' distance) - Complete Linkage (where finding the
maximal
clusters' distance) - Average Linkage (where finding the
Average
clusters' distance)
In Agglomerative clustering, there are ways of defining the distance between clusters A and B :
- Divisive:
- Works opposite as Agglomerative.
- At start, all observations are in one cluster. Split step by step until each observation is in its own cluster.
- (it is very slow compared to Agglomerative)
Types of Hierarchical Clustering
There are two kinds: Agglomerative 合 and Divisive 分
Divisive:
- Start with one, all-inclusive cluster
- At each step, split a cluster until each cluster contains a point (or there are k clusters)
Agglomerative:
- Works as opposite, Start with the points as individual clusters
- At each step, merge the closest pair of clusters until only one cluster (or k clusters) left
Since Agglomerative is the most popular one, here explains how it works:
- Compute distance matrix; let each data point be a cluster
- Repeat
2.1. Merge the two closest clusters
2.2. Update the distance matrix
- Until only a single cluster remains
There are 4 ways to Define Inter-Cluster Similarity :
- MIN
- MAX
- Group Average
- Distance Between Centroids
Of course, each of which has its own dis and advantage :
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ffd2f4b6c-d6da-4c29-a3fe-854f5ec82320%2FUntitled.png%3Ftable%3Dblock%26id%3Def6b145f-f7c6-4609-bb31-fa4e28df4905%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DsBA1wtTZGt7RHrpJtQMuwTqLYNCdRSPeucTIzLNz8_w?table=block&id=ef6b145f-f7c6-4609-bb31-fa4e28df4905&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F69fd720d-d3a5-4cb5-8a50-2a076ca65988%2FUntitled.png%3Ftable%3Dblock%26id%3D228b9677-5754-4468-aeaf-fce970c99eec%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3D5eYYXp_k-WU6Oo2jpZ_PLmT6ZyyLc8bP4V7lEZgqRxM?table=block&id=228b9677-5754-4468-aeaf-fce970c99eec&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F24331028-ed2f-4066-a247-29a505bab7f1%2FUntitled.png%3Ftable%3Dblock%26id%3D78ac4786-b28a-4e63-be40-aaf411050fbc%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DztTNJJKofF6gvx3QkWgnejDPmmtDG3q-lBKLzjRYv3k?table=block&id=78ac4786-b28a-4e63-be40-aaf411050fbc&cache=v2)
Assumption
Why and Why not HC?
Advantage
- It kinda compensates for what KNN cant do :
- Don’t need to assume any particular number of clusters
- Any desired number of clusters can be obtained by ‘cutting’ the dendrogram at the proper level
Disadvantage
Only works with a small dataset
Example
Brendi
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F5e0424b2-4368-4e0b-b65c-60579b4cc3fb%2Fchaining.jpeg%3Ftable%3Dblock%26id%3D8d70a1ef-52ef-4c61-bd87-502c71132167%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DJBnRJv_ENbgCgI5Gj4Vw23XnEBWHqopkDgBEmVwqeeY?table=block&id=8d70a1ef-52ef-4c61-bd87-502c71132167&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fa029482c-5ab7-4f41-b228-ed551b0ab431%2Flinkage.jpeg%3Ftable%3Dblock%26id%3Db0cd398a-017e-463e-ad62-fdea4ac96326%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3D1IFWxMeAwVhe9UqTKcbXg-8wN_fcyWpiN8F6_HuyM90?table=block&id=b0cd398a-017e-463e-ad62-fdea4ac96326&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Ff64bf654-e412-47c0-a493-d84cdfeeaac9%2Fchoosing-k.jpeg%3Ftable%3Dblock%26id%3Dc8ce620c-63b5-42a9-af34-82e5c4354aae%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DT5bJQ_alUbKUGVAOJJ-DywnT9cuRby_n7ut6Je_rVmY?table=block&id=c8ce620c-63b5-42a9-af34-82e5c4354aae&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F0738a5d7-93c7-40d1-9197-4df71a28b9ce%2Fhc.jpeg%3Ftable%3Dblock%26id%3D69f27022-4801-4c26-a7c4-a01b1f0e26a9%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3D9yOvd1B8oU5GbCAoJhtPJ27FrOVqB8VZLtkSt8l3aFY?table=block&id=69f27022-4801-4c26-a7c4-a01b1f0e26a9&cache=v2)
Bredwin
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F0047ecde-3585-4cf4-ad29-03726eced626%2Fcorr_distance_metric.jpeg%3Ftable%3Dblock%26id%3Ddc2f7b2a-f2e1-49e7-bc34-190378ff73d0%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DDtgoQuMNFyIHZlSRS-4HZfY1pwF7oYAfihLoc-Qf6iw?table=block&id=dc2f7b2a-f2e1-49e7-bc34-190378ff73d0&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F557eeebc-ae82-46f2-83af-780130cb16e1%2Fsingle_linkage_chaining.jpeg%3Ftable%3Dblock%26id%3Dc465cbf9-d6a3-4872-abe6-c567a2c54591%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DX6JRzQbtPOmH4bkM1wgHLmoQY7DTo2Qd9ybSlV-O0Fg?table=block&id=c465cbf9-d6a3-4872-abe6-c567a2c54591&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F2634ca5e-c66d-448b-bdc7-b6eff1a1ff8d%2Fsimple_hclust_eg.jpeg%3Ftable%3Dblock%26id%3D59351600-35e7-417b-be7b-fdf3ca14e96c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DNIoRygig0a-B40XqMMpVTM_lHLOrYmpFQI8ccfTwOAs?table=block&id=59351600-35e7-417b-be7b-fdf3ca14e96c&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F4ebba99b-3c51-4369-a197-2d0a2642f1b2%2Fdendogram.jpeg%3Ftable%3Dblock%26id%3De7ef52df-d486-483f-b092-6704761887a4%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DxaIyyv-Rv8Gv_ddRaTouMM0jzIFAhJYD5XcVh5Y3MEU?table=block&id=e7ef52df-d486-483f-b092-6704761887a4&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fba9343ce-2856-47a7-b7f0-5cc6981fc2ab%2Flinkage_methods.jpeg%3Ftable%3Dblock%26id%3D8b6ea712-9508-452e-85ec-3cf51c29bfb5%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DxnK_rsDm5TezUIifNHetymAGEnoI0W4s71n1y9_sq1I?table=block&id=8b6ea712-9508-452e-85ec-3cf51c29bfb5&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F4197df06-2efe-4588-a3b7-9f277bf7d38e%2Fcluster_validation_stats.jpeg%3Ftable%3Dblock%26id%3De32e276f-13ad-48a5-a8a8-5cb12b16d938%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DJHOLZYgyhtzpZ3wt7H9Xs8GObKqXfW40uTsc7zAf4qk?table=block&id=e32e276f-13ad-48a5-a8a8-5cb12b16d938&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F6fa52230-c563-4f59-88d1-ebf7965081bc%2Fcluster_validation_stats_intuition.jpeg%3Ftable%3Dblock%26id%3D968a7387-c82a-4336-ad2a-50f835677c05%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DOPnTOnKzkgM4mwk3fIlvUyBKtCkSP2vH63K-XnKGPKQ?table=block&id=968a7387-c82a-4336-ad2a-50f835677c05&cache=v2)
R code
```{r} # Read-in data data(flea, package = "tourr") # Standardise variables flea_std <- flea %>% mutate(across(where(is.numeric), ~ (.x - mean(.x, na.rm = TRUE)) / sd(.x, na.rm = TRUE))) ```
```{r} library(patchwork) # Compute distance matrix on standardised variables flea_dist <- flea_std %>% select(where(is.numeric)) %>% dist() # Hierarchical clustering for each method flea_hc_ward <- hclust(flea_dist, method = "ward.D2") flea_hc_single <- hclust(flea_dist, method = "single") # View dendrogram for each method p1 <- ggdendrogram(flea_hc_ward, rotate = TRUE, size = 4) + labs(title = "Ward.D2") p2 <- ggdendrogram(flea_hc_single, rotate = TRUE, size = 4) + labs(title = "Single") p1 / p2 ```
Plot dendrogram
interactive
identify(
flea_hc_ward )
plot(
flea_hc_ward )
ggdendrogram(
flea_hc_ward , rotate = TRUE, size = 4) + labs(title = "
ward.D2")
R interpretation
GGAnimate
Choose two cut the dendrograms at the 3 cluster solutions for each, creating new columns corresponding to the cluster label. Using a grand tour, examine the cluster solutions. Comment on which one best captures the cluster structure.
# Create cluster membership with 3-cluster solution flea_std <- flea_std %>% mutate(cl_ward = cutree(flea_hc_ward, k = 3), cl_single = cutree(flea_hc_single, k = 3))
# --- Grand tour animate_xy(flea_std[,1:6], col=flea_std$cl_ward) animate_xy(flea_std[,1:6], col=flea_std$cl_single) # Chaining
Ward Linkage
- The results from Wards linkage captures the three clusters that we see when we look at this 6D data in a tour.
- Its quite satisfying to see that it has discovered these clusters, based on interpoint distances.
Single Linkage
- The three cluster solution from single linkage has left all observations except two in one cluster.
- The two single points put in separate clusters could be considered to be outlying, in some directions in the 6D space.
- From the tour, you can see several more observations that might be considered to be outliers. If the single linkage dendrogram is cut further down, at 5 or 6 cluster solutions, these observations may also be placed in separate clusters, thus identifying them as outliers also.
For 2 through 10 clusters compute the cluster statistics, “within.cluster.ss”,“wb.ratio”, “ch”, “pearsongamma”, “dunn”, “dunn2”. What would be the conclusion on the number of clusters based on these metrics?
Brendi usually uses WB ratio and gamma
flea_vars <- flea_dist <- flea_std %>% select(where(is.numeric)) flea_hc_cl <- NULL; flea_hc_cl_stats <- NULL for (i in 2:10) { cl <- cutree(flea_hc_ward, i) x <- cluster.stats(dist(flea_vars[,-1]), cl) flea_hc_cl <- cbind(flea_hc_cl, cl) flea_hc_cl_stats <- rbind(flea_hc_cl_stats, c(i, x$within.cluster.ss, x$wb.ratio, x$ch, x$pearsongamma, x$dunn, x$dunn2)) } colnames(flea_hc_cl_stats) <- c("cl", "within.cluster.ss", "wb.ratio", "ch", "pearsongamma", "dunn", "dunn2") flea_hc_cl_stats <- as_tibble(flea_hc_cl_stats) flea_hc_cl_stats_long <- flea_hc_cl_stats %>% pivot_longer(-cl, names_to ="stat", values_to = "value") ggplot(data=flea_hc_cl_stats_long) + geom_line(aes(x=cl, y=value)) + xlab("# clusters") + ylab("") + facet_wrap(~stat, ncol=3, scales = "free_y") + theme_bw()
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F6c0fcf66-af8f-441a-a966-04b6a6775486%2FUntitled.png%3Ftable%3Dblock%26id%3De88f7dec-2956-464c-af07-13087c8f425b%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DKJkINImxJOoVKT9zs04ntGQwrN13Kyo9watZ8TN6RDU?table=block&id=e88f7dec-2956-464c-af07-13087c8f425b&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F4b2e01d5-3531-4461-a5c2-6b05bef5c2bc%2FUntitled.png%3Ftable%3Dblock%26id%3De7347211-e006-4e0d-9a21-2a468598a0e2%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DTdl3ob2-xhQDW7PUYnA5wAl31TQPcQrnfBjcQQTfbOk?table=block&id=e7347211-e006-4e0d-9a21-2a468598a0e2&cache=v2)
- wb.ratio : Average within cluster / Average between cluster
- preferably low,
- always drops for each additional cluster so look for large drops
- pearson gamma : Correlation between distances, a 0 and 1 vector where 0 means same cluster, 1 means different clusters
- If distance correlation is 0, X and Y are independent.
- preferably high
Further formula and comments from Di Cook
dunn minimum separation / maximum diameter. Dunn index, see Halkidi et al. (2002). dunn2 minimum average dissimilarity between two cluster / maximum average within cluster dissimilarity, another version of the family of Dunn indexes. would indicate that dunn2 is read the same way as dunn, higher the better. This particular example looks like it should be read in the opposite way. I would follow the function help, and consider it to be read the same - and ignore dunn2 anyway(!). (Otherwise I would need to go back to the original paper.)
Dendrogram
What is a dendrogram used in it?
- A ‘dendrogram’ shows how the clusters are merged hierarchically (looks like a tree diagram)
- It decomposes data objects into several levels of nested partitions (tree of clusters)
- The height represents the distance between clusters
- A clustering of the data objects is obtained by cutting the dendrogram at the desired level, and then each connected component forms a cluster
- a visualisation of the Hierarchical Clustering
How to interpret :
- Think of the axis with distance (y-axis) as the measuring a 'tolerance level'
- If the distance between two clusters is within the tolerance they are merged into one cluster.
- As tolerance increases more and more clusters are merged leading to less clusters overall.
Viewing Stability in Dendrogram
What is Stability?
Stability is the height between between cluster 1 and cluster (n-1), in the visualisation of dendrogram
- Aka Tolerance level
Changing tolerance (threshold) affect the Stability .
- The way to determine Stability is to look at the range of tolerance level.
I will give an illustration below :
![the range of tolerance level for cluster 1 > the range of tolerance level for cluster 2. Therefore, cluster 1 is more STABLE than cluster 2.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F16955a40-da7c-4f94-9ce1-ab8060b3b98f%2FUntitled.png%3Ftable%3Dblock%26id%3Dbf0ace2a-dddd-4c4e-a217-646eb80ce708%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DqLYYFvGNk1A6BvyMeh3Y_C1DUvVFrAIEFOsVMoYC84o?table=block&id=bf0ace2a-dddd-4c4e-a217-646eb80ce708&cache=v2)
FAQ
How to measure a distance between clusters in Hierarchical Clustering
Illustration
For agglomerative clustering
Single Linkage (aka. nearest neighbour
) (MIN)
The minimal distance between two points.
First, calculate all points between clusters,
Then find the minimum distance between two points, (which then becomes Single Linkage)
![This is to find the CLOSEST neighbor, which is shown below :](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F82e714fa-a655-41f7-88de-6077867517ca%2FUntitled.png%3Ftable%3Dblock%26id%3D23a48572-2a0c-49d1-8aa4-59616e000fb9%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3Dm02LGufqi9HkQd5G4jjeu0Uzp2i50NTZtOGx9YdnaaI?table=block&id=23a48572-2a0c-49d1-8aa4-59616e000fb9&cache=v2)
Complete Linkage (aka furthest neighbour
)(MAX)
The maximum distance between two points.
First, calculate all points between clusters,
Then, find the maximum distance between two points, (which then becomes a Single Linkage)
Pros and Cons of Single Linkage
This is to find the FURTHEREST neighbor, which is shown below :
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F5f12089a-8153-4b3d-b1db-3f583ee2bfc0%2FUntitled.png%3Ftable%3Dblock%26id%3Dfc0d0ac2-4b1b-48bf-9d3b-33bffecc228c%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DVxNE4kcsiW5mQpA1HzgCmx_ebuZLvOLdzFctjzXeS2I?table=block&id=fc0d0ac2-4b1b-48bf-9d3b-33bffecc228c&cache=v2)
Average Linkage (AVG)
Find the distance between two clusters is defined as the average distance
between each point in one cluster to every point in the other cluster.(From here)
Avg of all pairwise distances :
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fda95ac73-c2ee-448b-974c-957e58f1f1a2%2FUntitled.png%3Ftable%3Dblock%26id%3D9e564983-0fcf-4a33-ba6b-931ef2a15af0%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3Df81k0Lz0fhMe2yjjz84Yb30YXjzOFJL-wZUzZREVpio?table=block&id=9e564983-0fcf-4a33-ba6b-931ef2a15af0&cache=v2)
Centroid Method
distance between centroids (mean) of two clusters
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F0cd53348-1e85-4b1e-8526-a9320e314b41%2FUntitled.png%3Ftable%3Dblock%26id%3Dc4fe23da-2645-4f9a-84e5-24fc4f330b97%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3D-uHMp7SIXjU5KWotMknYh5sYHg2VsU3nr3Tl6_c7Hj0?table=block&id=c4fe23da-2645-4f9a-84e5-24fc4f330b97&cache=v2)
Ward's algorithm
Why
The most suitable method for quantitative variables.
Problem : Variance between distance
- Normally the distance between clusters is SAMLL where the variance is tiny. But When the distance is large, the variance is large as well.
Solution :
- Ward’s method merges two clusters to minimise within cluster variance.
How
- Instead of measuring the distance directly, it analyzes the variance of clusters.
- Ward’s method says that the distance between two clusters, A and B, is how much the sum of squares will increase when we merge them.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F72de81d5-c4c2-45bd-97c4-287bd7935c17%2FUntitled.png%3Ftable%3Dblock%26id%3D71347561-88ec-4427-a1e3-df88d27cdace%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DOgzi83aHH-yPsvCSQRxu4y2t0euuOldi38WVf-c_R7c?table=block&id=71347561-88ec-4427-a1e3-df88d27cdace&cache=v2)
The difference amongst MIN, MAX and AVG
Are there a correct number of clusters? If not, how to determine it
NO! But generally, DO NOT :
- choose too many clusters: (homogeneity within clusters)
- A firm developing a different marketing strategy for each market segment may not have the resources to develop a large number of unique strategies.
- choose too few clusters: (parsimony within clusters)
- If you choose the 1-cluster solution there is no point in doing clustering at all.
How can we know when to use Single Linkage or Complete Linkage? (Pros and Cons)
What is Chaining? (found on Cons of Single Linkage in ETF3500 p.56)
Chaining is a problem that occurs when clusters are not compact and some observations in the same cluster are far away from one another.
![notion image](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2Fcccb35de-d830-43c8-bfc0-57c40ab8f494%2FUntitled.png%3Ftable%3Dblock%26id%3Deb8d8a24-0b79-471e-b45e-e9a2f8b8c577%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DEtfEa6HAYkKT67s95HyJ4wboq-9qFdORhPCm_bZEVeI?table=block&id=eb8d8a24-0b79-471e-b45e-e9a2f8b8c577&cache=v2)
What is in-lier?
Points that are between major clusters of data. Affect some linkage methods, eg single, which will tend to "chain" thru the data grping everything tgt.
What is the difference between the centroid and average linkage method?
- In average linkage
- Compute the distances between pairs of observations
- Average these distances
Illustration
![This method involves looking at the distances between all pairs and averages all of these distances](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F39ec8988-1073-423b-b48f-b11db35a51a8%2FUntitled.png%3Ftable%3Dblock%26id%3De1823ff7-fb1a-448b-a1e9-7d4e9e8823f2%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3D-uBVdH6G61TUqVA4ATABpxgk7V2xbrodLDI9ien0vVY?table=block&id=e1823ff7-fb1a-448b-a1e9-7d4e9e8823f2&cache=v2)
- In the centroid method
- Average the observations to obtain the centroid of each cluster.
- Find the distance between centroids
Illustration
![This involves finding the mean vector location for each of the clusters and taking the distance between the two centroids.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F90e5c481-e80c-4f44-a062-78c7cd38d73b%2FUntitled.png%3Ftable%3Dblock%26id%3D9d5d6a42-6da8-4852-9788-d45026edb62d%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3Dj8eb-WgSfvRUNIh1DfOhYTE3LZjZcWr5nfU9uWp8yEY?table=block&id=9d5d6a42-6da8-4852-9788-d45026edb62d&cache=v2)
What is Stability?
Stability is the height between between cluster 1 and cluster (n-1), in the visualisation of dendrogram
- Aka Tolerance level
Changing tolerance (threshold) affect the Stability .
- The way to determine Stability is to look at the range of tolerance level.
I will give an illustration below :
![the range of tolerance level for cluster 1 > the range of tolerance level for cluster 2. Therefore, cluster 1 is more STABLE than cluster 2.](https://www.notion.so/image/https%3A%2F%2Ffile.notion.so%2Ff%2Ff%2Fe1c5ba0e-562a-49b0-8505-ce5e38fc061b%2F16955a40-da7c-4f94-9ce1-ab8060b3b98f%2FUntitled.png%3Ftable%3Dblock%26id%3Dbf0ace2a-dddd-4c4e-a217-646eb80ce708%26spaceId%3De1c5ba0e-562a-49b0-8505-ce5e38fc061b%26expirationTimestamp%3D1725832800000%26signature%3DqLYYFvGNk1A6BvyMeh3Y_C1DUvVFrAIEFOsVMoYC84o?table=block&id=bf0ace2a-dddd-4c4e-a217-646eb80ce708&cache=v2)
What is Robust? Is Single Linkage (MIN) Robust? (only in Hierarchical)
- Robust means the analysis does not dramatically change, even adding a single observation.
- To Single Linkage (MIN) Robust :
- In this instance, the new observation was not even an outlier but called inlier.
- Methods that are not affected by single observations are often called robust.
What are the linkages besides Single and Complete? Why do we prefer using them to SL or CL?
Average Linkage
Centroid method
Ward’s Method
They should be used because they are robust (i.e. Not sensitive to outliers)
Complete linkage avoids chaining, but suffers from crowding
What is centroid?
The center of a cluster
When do we use hierarchical and non-hierarchical cluster techniques
Although both algorithms can be used in the analysis, hierarchical are suited to small data sets (since the dendrogram can be more easily interpreted) while non-hierarchical methods are well suited to large data sets.
What are the advantages and disadvantages of hierarchical & non-hierarchical clustering
Hierarchical: are sequential either building up from separate clusters or breaking down from the one cluster.
Non-hierarchical: The number of clusters is chosen a priori.
Advantages of Hierarchical clustering
- All possible solutions (with respect to the number of clusters) is provided in a single analysis
- It is structured and can be explored using the dendrogram.
- Don’t need to assume any particular number of clusters. Any desired number of clusters can be obtained by ‘cutting’ the dendrogram at the proper level
Advantages of K-Means Clustering
- Can explore cluster allocations that will never be visited by the path of hierarchical solutions.
- With a large number of variables, if K is small, K-Means may be computationally faster than hierarchical clustering.
- K-Means might yield tighter clusters than hierarchical clustering
- An instance can change cluster (move to another cluster) when the centroids are recomputed.
Disadvantages of Hierarchical clustering
- It is not possible to undo the previous step: once the instances have been assigned to a cluster, they can no longer be moved around.
- Time complexity: not suitable for large datasets
- Very sensitive to outliers
Disadvantages of Hierarchical clustering
- Need to assume any particular number of clusters (K-Value), which is hard to predict.
- Initial seeds (centers of each cluster) have a strong influence on the final results
- Sensitive to scale.
Rand Index
What is Rand Index
- The probability of picking two observations at random that are in agreement.
- Lies between 0 and 1 and higher numbers indicate agreement.
- Express what proportion of the cluster assignments are ‘correct’.
Problems : Even if observations are clustered at random, there will still be some agreement due to chance.
Solution — Adjusted Rand Index
- Can use adjustedRandIndex() in the package of
mclust
Interpretation
0
= if the level of agreement equals the case where clustering is done at random.
1
= if the two clustering solutions are in perfect agreement. (Good)
Can Rand Index be the same, if solution A is a three-cluster solution and solution B is a two-cluster solution. Given that they are done from the same dataset
No.
Math
Reference
Slides [Slides]
Extra Resource
Practice
- Author:Jason Siu
- URL:https://jason-siu.com/article/a80e5c4f-2d45-4026-aabc-db9687e84032
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts