Dans une étude 2 caractères: X1 et X2 sur 6 individus w1,w2,w3,w4,w5,w6 :
w1 | w2 | w3 | w4 | w5 | w6 | |
---|---|---|---|---|---|---|
X1 | -2 | -2 | 2 | 2 | -2 | 3 |
X2 | 2 | -1 | 0 | 2 | 3 | 0 |
On fait une classification avec des centres initiaux
Remarque:
𝑠𝑜𝑛𝑡 𝑑𝑒𝑠 𝑐ℎ𝑜𝑖𝑥 𝑝𝑠𝑒𝑢𝑑𝑜−𝑎𝑟𝑏𝑖𝑡𝑟𝑎𝑖𝑟𝑒𝑠 ‼!
Code R:
x = c(-2, -2, 0, 2, -2, 3, 2, -1, -1, 2, 3, 0)
m = matrix(x, ncol = 2, nrow = 6)
clus = kmeans(m, centers=rbind(c(-1, 2), c(1, 1)), algorithm = "Lloyd")
clus$cluster
clus$centers
plot(m, col = clus$cluster, pch = 1, lwd = 3, xlab = "X1", ylab = "X2")
points(clus$centers, col = 1:2, pch = 9, lwd = 3)
|
---|
Le résultat: