-
Notifications
You must be signed in to change notification settings - Fork 0
/
01clusterHier.R
103 lines (82 loc) · 2.43 KB
/
01clusterHier.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
setwd("~/git_repos/cluster-examples/")
# Cusion dataset ---------------------------------------------------------
dat01 <- read.table("data/01cusion.csv",
header=T,
sep=",")
head(dat01)
plot(y~x,
col=as.numeric(as.factor(group)),
data=dat01)
cl01 <- hclust(dist(dat01[,1:2]), method = "complete")
cl01wd <- hclust(dist(dat01[,1:2]), method = "ward.D")
cl01wd2 <- hclust(dist(dat01[,1:2]), method = "ward.D2")
cl01single <- hclust(dist(dat01[,1:2]), method = "single")
cl01average <- hclust(dist(dat01[,1:2]), method = "average")
cl01mcquitty <- hclust(dist(dat01[,1:2]), method = "mcquitty")
cl01median <- hclust(dist(dat01[,1:2]), method = "median")
cl01centroid <- hclust(dist(dat01[,1:2]), method = "centroid")
cutree(cl01, k=2)
plot(y~x,
col=cutree(cl01, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01wd, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01wd2, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01average, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01centroid, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01median, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01mcquitty, k=2),
data=dat01)
plot(y~x,
col=cutree(cl01single, k=2),
data=dat01)
# Swirl data --------------------------------------------------------------
dat02 <- read.table("data/02swirl.csv",
header=T,
sep=",")
head(dat02)
plot(y~x,
col=as.numeric(as.factor(group)),
data=dat02)
cl02 <- hclust(dist(dat02[,1:2]), method = "complete")
cl02wd <- hclust(dist(dat02[,1:2]), method = "ward.D")
cl02wd2 <- hclust(dist(dat02[,1:2]), method = "ward.D2")
cl02single <- hclust(dist(dat02[,1:2]), method = "single")
cl02average <- hclust(dist(dat02[,1:2]), method = "average")
cl02mcquitty <- hclust(dist(dat02[,1:2]), method = "mcquitty")
cl02median <- hclust(dist(dat02[,1:2]), method = "median")
cl02centroid <- hclust(dist(dat02[,1:2]), method = "centroid")
plot(y~x,
col=cutree(cl02, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02wd, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02wd2, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02average, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02centroid, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02median, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02mcquitty, k=2),
data=dat02)
plot(y~x,
col=cutree(cl02single, k=2),
data=dat02)