rm(list=ls())
library(cluster)
library(mixtools)
kmdata = read.csv("kmdata.txt")
target = kmdata[, 3]
kmdata = kmdata[, 1:2]
# Q1
plot(kmdata, col=target)
# Q2
model = kmeans(kmdata, 3)
plot(kmdata, col=model$cluster)
# Q3
model = mvnormalmixEM(kmdata, k = 3, epsilon = 0.0001)
plot(model, which = 2)
# Alternatively use this
# clusters = max.col(model$posterior)
# centers = matrix(unlist(model$mu), byrow = TRUE, ncol = 2)
# plot(gsdata, col = clusters)
# points(centers, col = 4, pch = "+", cex = 2)
# for (i in 1:3) ellipse(mu = model$mu[[i]], sigma = model$sigma[[i]])
Comments