Question: Please use the code here to answer the question from c to g Thanks! set.seed(123) n=20;p=50;s=10;mu1=c(rep(1,s),rep(0,p-s)); mu2=c(rep(0,s),rep(1,s),rep(0,p-2*s)); mu3=c(rep(0,s),rep(0,s),rep(1,s),rep(0,p-3*s)); x1=matrix(rnorm(n*p),n,p)+mu1; x2=matrix(rnorm(n*p),n,p)+mu2 x3=matrix(rnorm(n*p),n,p)+mu3 features=rbind(x1,x2,x3) cat=c(rep(A,n),rep(B,n),rep(C,n)) sim.data=data.frame(Class=cat,x=features) (c)
Please use the code here to answer the question from c to g Thanks!
set.seed(123) n=20;p=50;s=10;mu1=c(rep(1,s),rep(0,p-s)); mu2=c(rep(0,s),rep(1,s),rep(0,p-2*s)); mu3=c(rep(0,s),rep(0,s),rep(1,s),rep(0,p-3*s)); x1=matrix(rnorm(n*p),n,p)+mu1; x2=matrix(rnorm(n*p),n,p)+mu2 x3=matrix(rnorm(n*p),n,p)+mu3 features=rbind(x1,x2,x3) cat=c(rep("A",n),rep("B",n),rep("C",n)) sim.data=data.frame(Class=cat,x=features)
(c) Perform K-means clustering of the observations with K = 3. How well do the clusters that you obtained in K-means clustering compare to the true class labels? Hint: You can use the table() function in R to compare the true class labels to the class labels obtained by clustering. Be careful how you interpret the results: K-means clustering will arbitrarily number the clusters, so you cannot simply check whether the true class labels and clustering labels are the same.
(d) Perform K-means clustering with K = 2. Describe your results.
(e) Now perform K-means clustering with K = 4, and describe your results.
(f) Now perform K-means clustering with K = 3 on the first two principal component score vectors, rather than on the raw data. That is, perform K-means clustering on the 60 2 matrix of which the first column is the first principal component score vector, and the second column is the second principal component score vector. Comment on the results.
(g) Using the scale() function, perform K-means clustering with K = 3 on the data after scaling each variable to have standard deviation one. How do these results compare to those obtained in (b)? Explain.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
