-
Notifications
You must be signed in to change notification settings - Fork 2
/
03-02-Hierarchical-Clustering.Rmd
48 lines (37 loc) · 1.46 KB
/
03-02-Hierarchical-Clustering.Rmd
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
## Hierarchical Clustering {-}
```{r a2, warning=FALSE, message=FALSE, comment=NA, fig.width=8, fig.height=7}
library(cluster)
## Hierarchical clustering using the mtcars dataset
##
## Data description from R:
## The data was extracted from the 1974 Motor Trend US magazine, and comprises
## fuel consumption and 10 aspects of automobile design and performance for
## 32 automobiles (1973-74 models).
##
## Since the attributes have different scales we need to standardize them
cars.dist = dist(scale(mtcars, center = TRUE, scale = TRUE))
## Clustering by rows (cars)
## Method Average, average distance between all points in a cluster
plot(hclust(cars.dist, method = "average"), xlab = "", ylab ="Distance")
## Method Single, shortest distance between each cluster
plot(hclust(cars.dist, method = "single"), xlab = "", ylab ="Distance")
## Method Complete, longest distance between each cluster
plot(hclust(cars.dist, method = "complete"), xlab = "", ylab ="Distance")
## Method Ward, minimizes the loss of exmplained variance
plot(hclust(cars.dist, method = "ward.D"), xlab = "", ylab ="Distance")
## Attribute Descriptions:
##
## mpg Miles/(US) gallon
## cyl Number of cylinders
## disp Displacement (cu.in.)
## hp Gross horsepower
## drat Rear axle ratio
## wt Weight (lb/1000)
## qsec 1/4 mile time
## vs V/S
## am Transmission (0 = automatic, 1 = manual)
## gear Number of forward gears
## carb Number of carburetors
## Data and Summary
mtcars; summary(mtcars)
```