# SOM (Kohonen) using the term document matrix [closed]

Language: R

Package: kohonen

Function: som

I have a term document matrix (tdm) with 64 terms (row) and 1017 documents (columns). I want to use the self-organized-map to cluster the terms on 25 cells. In order to do that I have done:

somres <- som(as.matrix(tdm), grid=somgrid(ydim=5, xdim=5, 'hexagonal'))

• My target: I want to map every single term on the 25 cells to see how it varies on them.
• What I need: I'm looking for an object with 5x5 = 25 rows and 64 columns (or viceversa) in which I have 25 codebooks, and a vector with 64 values for each codebook (one for each term). I need it to map a single term on the 25 cells.

I cannot find it on the object somres (I have seen all the attributes on it). Do you have some ides before I change the package?

EDIT: the problem was simply in the fact that I used the "term document matrix" as input. If you use the "document term matrix" (package: koRpus) it works well. What I was looking for, in that case, is in somres$codes. ## 1 Answer Have you looked at kohonen's plot function? You can use the type="mapping" to show where objects (rows) are mapped, for example. Also, if you do str (somres), you'll see its contents, which includes unit.classif. EDIT: Whoops, missed the fact that you've looked into somres already. You'll have to make the array you want from what you've got. Since plot can do it, it's possible. You might also want to look at map in kohonen. • Thank you Wayne. In this case the solution was another one: in somres$codes there was the solution, but it was wrong. That happened because I used in input the term-document-matrix (tdm). All works well if I use the document-term-matrix instead. Feb 10, 2016 at 16:42
• Yes, kohonen will be row-oriented, so you had to transpose the matrix. Feb 10, 2016 at 16:50