Exploring mtcars via k-means clustering
Victor Bernal
Mon Sep 30 17:10:37 2019
The mtcars data comes from the 1974 Motor Trend US magazine. It presents 32 vehicles, with some design/ and performance features. We want to explore how these features separate automobile in classes!
head(mtcars[,c(1:3)])
mpg cyl disp
Mazda RX4 21.0 6 160
Mazda RX4 Wag 21.0 6 160
Datsun 710 22.8 4 108
Hornet 4 Drive 21.4 6 258
Hornet Sportabout 18.7 8 360
Valiant 18.1 6 225
clusters<-kmeans(mtcars[, c(1,2)], 3)
plot(mtcars[, c(1)],mtcars[, c(2)],
col = clusters$cluster,
pch = 20, cex = 3*(scale(mtcars[,5])+2),
xlab=colnames(mtcars)[1], ylab=colnames(mtcars)[2])
points(clusters$centers, pch = 1, cex = 4, lwd = 4)