[R] how to label the som notes by the majority vote

Changbin Du changbind at gmail.com
Wed Jun 2 02:21:51 CEST 2010


HI, Dear R community,

I am using the following codes to do the som. I tried to label the notes by
the majority vote. either through mapping or prediction.
I attached my output, the left one dont have any labels in the note, the
right one has  more than one label in each note. I need to have only one
label for each note either by majority vote or prediction.

Can anyone give some suggestions or advice? Thanks so much!



alex<-read.table("/home/cdu/operon/alex2.txt", , sep="\t", skip=0, header=T,
fill=T)
alex1<-alex[,c(1:257)]
levels(alex1$Label)

alex1$outcome<-as.numeric(alex1$Label)
alex1$outcome[1:20]


#self-organizing maps(unsupervised learning)
library("kohonen")


#SOM, the supervised learning, train the map using outcome as the class
variable.
set.seed(13)
final.xyf<- xyf(data=as.matrix(alex1[,c(1:256)]),
Y=classvec2classmat(alex1$outcome), xweight = 0.99, grid=somgrid(20, 30,
"hexagonal"))


outcome.xyf <- predict(final.xyf)$unit.prediction#get prediction
outcome.predict<- as.numeric(classmat2classvec(outcome.xyf)) #change matrix
to vectors.

outcome.label<-LETTERS[outcome.predict] #conver the numeric value to
letters.


plot(final.xyf, type="property", property=outcome.predict,
labels=outcome.label, palette.name =rainbow, main="Prediction ")



cl <- colors()
bgcols <- cl[2:14]
plot(final.xyf, type="mapping", labels=outcome.label, col="black",
bgcol=bgcols[as.integer(outcome.predict)],
          main="Mapping plot")




-- 
Sincerely,
Changbin
--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: som_alex.pdf
Type: application/pdf
Size: 366947 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100601/11babd68/attachment-0001.pdf>


More information about the R-help mailing list