Review of hierarchical clustering

Unsupervised Learning in R

Hank Roark

Senior Data Scientist at Boeing

Hierarchical clustering review

# Fitting various hierarchical clustering models
hclust.complete <- hclust(d, method = "complete")
hclust.average <- hclust(d, method = "average")
hclust.single <- hclust(d, method = "single")
Unsupervised Learning in R

Linking methods: complete and average

complete and average linking methods dendrogram

Unsupervised Learning in R

Hierarchical clustering

Unsupervised Learning in R

Iterating

iterating to get more clusters

Unsupervised Learning in R

Dendrogram

5 clusters and a finished dendrogram

Unsupervised Learning in R

How k-means and hierarchical clustering differ

k-means vs dendrogram

Unsupervised Learning in R

Practical matters

# Scale the data
pokemon.scaled <- scale(pokemon)

# Create hierarchical and k-means clustering models
hclust.pokemon <- hclust(dist(pokemon.scaled), method = "complete")
km.pokemon <- kmeans(pokemon.scaled, centers = 3,
                     nstart = 20, iter.max = 50)

# Compare results of the models
cut.pokemon <- cutree(hclust.pokemon, k = 3)
table(km.pokemon$cluster, cut.pokemon)
cut.pokemon
    1   2   3
1 242   1   0
2 342   1   0
3 204   9   1
Unsupervised Learning in R

Let's practice!

Unsupervised Learning in R

Preparing Video For Download...