(15 points) 3. Consider the following data set shown in Table 2. Place the objects in the data set in two clusters using
Posted: Fri Apr 29, 2022 6:51 am
this is the code I have so far.
f <= file.choose("Social.csv")
df <- read.csv("Social.csv")
data("Social")
summary(Social)
head(Social)
Social <-data("Social")
storm_data1 <- select(Social, c(1:9))
data <- selectc(Social,2:5)
kmean <- kmeans(data,5)
kmean$centers
kmean$cluster
autoplot(kmean, data, frame = TRUE)
wssplot <- function(data, nc=15, seed=1234){
wss <- (nrow(data)-1)*sum(apply(data,2,var))
for (i in 2:nc){
set.seed(seed)
wss <- sum(kmeans(data,
centers=i)$withinss)}
plot(1:nc, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of
squares")
wss
}
wssplot(data)
(15 points) 3. Consider the following data set shown in Table 2. Place the objects in the data set in two clusters using k-means. Andrew and Carolina are selected as the initial centroids of the two clusters. Find the cluster to which each object belongs to using k-means with one iteration and re-compute the centroids of the two clusters. Create a scatter plot for the data set and the re- computed centroids. The cluster to which each object belongs to is represented by color of the object in the plot. A B с 11 1 Name Age Educational level 2 Andrew (A) 55 1 А B с 3 Bernhard (B) 43 2 4 37 5 Carolina (C) Dennis (D) 5 82 3 6 Eve (E) 23 3.2 7 Fred (F) 46 5
f <= file.choose("Social.csv")
df <- read.csv("Social.csv")
data("Social")
summary(Social)
head(Social)
Social <-data("Social")
storm_data1 <- select(Social, c(1:9))
data <- selectc(Social,2:5)
kmean <- kmeans(data,5)
kmean$centers
kmean$cluster
autoplot(kmean, data, frame = TRUE)
wssplot <- function(data, nc=15, seed=1234){
wss <- (nrow(data)-1)*sum(apply(data,2,var))
for (i in 2:nc){
set.seed(seed)
wss <- sum(kmeans(data,
centers=i)$withinss)}
plot(1:nc, wss, type="b", xlab="Number of Clusters",
ylab="Within groups sum of
squares")
wss
}
wssplot(data)
(15 points) 3. Consider the following data set shown in Table 2. Place the objects in the data set in two clusters using k-means. Andrew and Carolina are selected as the initial centroids of the two clusters. Find the cluster to which each object belongs to using k-means with one iteration and re-compute the centroids of the two clusters. Create a scatter plot for the data set and the re- computed centroids. The cluster to which each object belongs to is represented by color of the object in the plot. A B с 11 1 Name Age Educational level 2 Andrew (A) 55 1 А B с 3 Bernhard (B) 43 2 4 37 5 Carolina (C) Dennis (D) 5 82 3 6 Eve (E) 23 3.2 7 Fred (F) 46 5