In SOM, (how) can I extract rows in each cluster?
1
0
Entering edit mode
5.9 years ago

In SOM clustering, (how) can I extract rows in each cluster?

library(kohonen)
a= matrix (rnorm(4000),500 )
row.names(a)= paste('r', 1:500, sep='')
s= som (a, grid= somgrid ( 3,4,'hexagonal'))
plot (s)

I used either

s$data
s$codes

with no success. Thank you in advance.

som cluster members • 2.1k views
ADD COMMENT
4
Entering edit mode
5.9 years ago

These are held in the unit.classif object. For example, I re-ran your code and my random data-matrix produced 12 clusters. A quick check of unit.classif reveals 12 categorical levels:

levels(factor(s$unit.classif))
 [1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10" "11" "12"

You can then create a simple data-frame with the assignments, along with each row's distance to its respective assigned cluster:

res <- data.frame(rownames(a), s$distances, s$unit.classif)
colnames(res) <- c("rowname","distFromClus","Cluster")
res[1:20,]
   rowname distFromClus Cluster
1       r1     6.705452      11
2       r2     3.816565       3
3       r3     3.501137       5
4       r4     4.911634       2
5       r5     6.684077       6
6       r6    10.983671      11
7       r7     8.375258       3
8       r8     1.739472       3
9       r9     3.370915      12
10     r10     3.411521       1
11     r11     4.112711       8
12     r12     3.161650       4
13     r13     3.938754       5
14     r14     3.193206      12
15     r15     5.757975       6
16     r16     4.449785      11
17     r17     4.633186      11
18     r18     5.883848       8
19     r19    10.179297       4
20     r20     3.014707       2

Kevin

ADD COMMENT
0
Entering edit mode

Thank you indeed very much. It works.

ADD REPLY
1
Entering edit mode

You're welcome, english.server

ADD REPLY

Login before adding your answer.

Traffic: 2555 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6