0% found this document useful (0 votes)
43 views4 pages

STAT202-lecture2 Project6

Uploaded by

Bao Gan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

STAT202-lecture2 Project6

Uploaded by

Bao Gan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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:
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

You might also like