Thanks, Joris! It works! I appreciated!
On Wed, Jun 2, 2010 at 4:23 AM, Joris Meys <jorism...@gmail.com> wrote: > Hi Changbin, > > I looked at your code again, and it appears as if you're using the mapping > plot for something that it isn't meant for. The mapping shows you how many > points you have in every circle, and these points are represented by the > labels. Your first plot gives the majority vote. > > This said, you can hack the function using: > > classif <- predict(nir.xyf) > tmp <- table(classif$unit.classif,classif$prediction) > label <- colnames(tmp) > label <- apply(tmp!=0,1,function(x){label[x]})[classif$unit.classif] > label[-match(1:16,classif$unit.classif)] <- "" > > > cl <- colors() > bgcols <- rev(heat.colors(4)) > plot(nir.xyf, > type="mapping",bgcol=bgcols[as.numeric(as.factor(temp.predict))], > main="Mapping plot",labels=label) > > It does not calculate the majority vote itself, it just assigns a label to > the category based on the predicted labels. Which is equivalent in this > case. > > Cheers > Joris > > > On Wed, Jun 2, 2010 at 5:08 AM, Changbin Du <changb...@gmail.com> wrote: > >> >> library("kohonen") >> data(nir) >> attach(nir) >> >> #SOM, the supervised learning, train the map using temperature as the >> class variable. >> set.seed(13) >> nir.xyf<- xyf(data=spectra, Y=classvec2classmat(temperature), xweight = >> 0.9, grid=somgrid(4, 4, "hexagonal")) >> >> >> temp.xyf <- predict(nir.xyf)$unit.prediction #get prediction >> temp.predict<- as.numeric(classmat2classvec(temp.xyf)) #change matrix to >> vectors. >> >> par(mfrow=c(1,2)) >> >> plot(nir.xyf, type="property", property=temp.predict, palette.name=rainbow, >> main="Prediction ") >> >> >> cl <- colors() >> bgcols <- cl[2:14] >> plot(nir.xyf, type="mapping", labels=nir$temperature, >> bgcol=bgcols[as.integer(temp.predict)], >> main="Mapping plot") >> >> par(mfrow=c(1,1)) >> >> >> >> HI, Joris, >> >> Thanks so much for your suggestion! I have modified the above codes, and >> what I want is to label the notes by the temperature. >> if a note has 3 objects mapped to it (the temperature are 30, 40, 30), >> then I want the 30 be labeled on the note. >> >> the right plot is the mapping plot, I want it to be labeled by only one >> temperature. >> >> Thanks so much! >> >> >> >> >> >> >> >> >> >> >> >> On Tue, Jun 1, 2010 at 5:36 PM, Joris Meys <jorism...@gmail.com> wrote: >> >>> Dear Changbin, >>> >>> Please provide a self-contained, minimal example, meaning the whole code >>> should run and create the plot as it is now, without having to load your >>> dataset (which we don't have). Otherwise it's impossible to see what's going >>> on and help you. >>> >>> Cheers >>> Joris >>> >>> On Wed, Jun 2, 2010 at 2:21 AM, Changbin Du <changb...@gmail.com> wrote: >>> >>>> 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 >>>> -- >>>> >>>> ______________________________________________ >>>> R-help@r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide >>>> http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >>>> >>>> >>> >>> >>> -- >>> Joris Meys >>> Statistical Consultant >>> >>> Ghent University >>> Faculty of Bioscience Engineering >>> Department of Applied mathematics, biometrics and process control >>> >>> Coupure Links 653 >>> B-9000 Gent >>> >>> tel : +32 9 264 59 87 >>> joris.m...@ugent.be >>> ------------------------------- >>> Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php >>> >> >> >> >> -- >> Sincerely, >> Changbin >> -- >> >> >> > > > -- > Joris Meys > Statistical Consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Applied mathematics, biometrics and process control > > Coupure Links 653 > B-9000 Gent > > tel : +32 9 264 59 87 > joris.m...@ugent.be > ------------------------------- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > -- Sincerely, Changbin -- [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.