Nevethan / SM-Exercises

0 stars 0 forks source link

3.2 Hierarchical clustering #2

Open anna0207 opened 6 years ago

anna0207 commented 6 years ago

3.2.1: Show level dendrogram containing 5 instances of each digit (one person)

3.2.2: Use K-Mean clustering to compress each digit into 5 clusters, as done in 3.1.1, and perform hierarchical clustering to show a low level dendrogram of this (one person).

3.2.3: Discuss the results and relate them to the cross validation tables from k-NN classification.

anna0207 commented 6 years ago

R-code example for create dendrogram with hierarchical clustering:

Import packages (or install)

library(cluster) library(dendextend)

Standardizing

data.norm <- scale(data)

Dissimilarity function

fun <- function(x) as.dist((1-cor(t(x)))/2)

Calculate dissimilarity matrix

data.dis <- fun(data.norm)

Calculate hierarchical clustering (method is type of linkage)

data.hclust <- hclust(data.dis, method="ward.D2")

Plot different dendrograms

plot(data.hclust) plot(as.dendrogram(data.hclust)) plot(as.dendrogram(agnes(data))) plot(as.dendrogram(diana(data)))