STAT202-lecture2 Project6
STAT202-lecture2 Project6
Solution:
x<-read.csv("cluster.csv",header=F)
plot(x,pch=19,xlab=expression(x[1]),
ylab=expression(x[2]))
fit<-kmeans(x, 2)
points(fit$centers,pch=19,col="blue",cex=2)
21
In class exercise #41:
Use kmeans() in R with all the default values to find the
k=2 solution for the 2-dimensional data at
http://sites.google.com/site/stats202/data/cluster.csv
Plot the data. Also plot the fitted cluster centers using
a different color. Color the points according to their
cluster membership.
Solution (continued):
points(x,col=fit$cluster,pch=19)
22
In class exercise #41:
Use kmeans() in R with all the default values to find the
k=2 solution for the 2-dimensional data at
http://sites.google.com/site/stats202/data/cluster.csv
Plot the data. Also plot the fitted cluster centers using
a different color. Color the points according to their
cluster membership.
Solution (continued):
23
In class exercise #42:
Use kmeans() in R with all the default values to find the
k=2 solution for the first two columns of the sonar
training data at
http://sites.google.com/site/stats202/data/sonar_train.csv
Plot these two columns. Also plot the fitted cluster
centers using a different color. Color the points
according to their cluster membership.
24