Hi, I am working on ranking algo? I have data which is in the form of vectors (feature) for each class and i need to rank them based on feature vector. class1<-c(1,3,4,-2,0) class2<-c(2,0,0,-3,0) class3<-c(2,3,1,4,5) class4<-c(-4,-5,1,0,0) I need to rank class1, class2, class3, class4 & class5. How can i implement it? Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-rank-vectors-based-on-their-elements-tp4558409p4558409.html Sent from the R help mailing list archive at Nabble.com.
This question is too vague. There are probably an infinite number of ways to rank them. Are apples better than bananas? Is the second element of the vector more important than the third? By how much? --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. Manish Gupta <mandecent.gupta at gmail.com> wrote:>Hi, > >I am working on ranking algo? I have data which is in the form of >vectors >(feature) for each class and i need to rank them based on feature >vector. > >class1<-c(1,3,4,-2,0) >class2<-c(2,0,0,-3,0) >class3<-c(2,3,1,4,5) >class4<-c(-4,-5,1,0,0) > >I need to rank class1, class2, class3, class4 & class5. How can i >implement >it? > >Regards > >-- >View this message in context: >http://r.789695.n4.nabble.com/How-to-rank-vectors-based-on-their-elements-tp4558409p4558409.html >Sent from the R help mailing list archive at Nabble.com. > >______________________________________________ >R-help at 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.
Thanks for your reply. But the classes are having weighht vectors? so we know alredy each elelment (here 5) has their own signicance which is shown by negative and positive values. But i need to use this data to rank them. Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-rank-vectors-based-on-their-elements-tp4558409p4558638.html Sent from the R help mailing list archive at Nabble.com.
On Sat, Apr 14, 2012 at 07:10:48PM -0700, Manish Gupta wrote:> Hi, > > I am working on ranking algo? I have data which is in the form of vectors > (feature) for each class and i need to rank them based on feature vector. > > class1<-c(1,3,4,-2,0) > class2<-c(2,0,0,-3,0) > class3<-c(2,3,1,4,5) > class4<-c(-4,-5,1,0,0) > > I need to rank class1, class2, class3, class4 & class5. How can i implement > it?Hi. I am not sure, whether i understand, what you mean. How many examples of each class do you have? Do you have one example for each class consisting of 5 features or you have 5 examples for each class, where each example is represented by a single number? The usual format for a classification task is a matrix or data frame with one column for each feature and one column for the class. The first interpretation would be represented by the matrix 1 3 4 -2 0 class1 2 0 0 -3 0 class2 2 3 1 4 5 class3 -4 -5 1 0 0 class4 and the other interpretation would be represented by 1 class1 3 class1 4 class1 -2 class1 0 class1 2 class2 0 class2 0 class2 -3 class2 0 class2 2 class3 3 class3 1 class3 4 class3 5 class3 -4 class4 -5 class4 1 class4 0 class4 0 class4 Is some of this meaningful in your application? What do you mean by ranking? Do you mean to estimate to which class belongs a new example not contained in the data above? Another understanding may be that you want to order the four classes by some type of average of the numbers assigned to each of them. Petr Savicky.
Hi, In my case, your first guess is right. I need to rank classes based on their feature vector. 1 3 4 -2 0 class1 2 0 0 -3 0 class2 2 3 1 4 5 class3 -4 -5 1 0 0 class4 Like class1 > class3> class4> class2 How can i implement it? Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-rank-vectors-based-on-their-elements-tp4558409p4558829.html Sent from the R help mailing list archive at Nabble.com.
On Sun, Apr 15, 2012 at 02:52:11AM -0700, Manish Gupta wrote:> Hi, > > > In my case, your first guess is right. I need to rank classes based on > their feature vector. > > 1 3 4 -2 0 class1 > 2 0 0 -3 0 class2 > 2 3 1 4 5 class3 > -4 -5 1 0 0 class4 > > Like class1 > class3> class4> class2 > > How can i implement it?Hi. The ordering may be defined in many ways depending on the purpose of the ordering. Since i do not know this purpose, i can only guess, what can be meaningful. Try the ordering by the mean value. This can be done as follows. class1<-c(1,3,4,-2,0) class2<-c(2,0,0,-3,0) class3<-c(2,3,1,4,5) class4<-c(-4,-5,1,0,0) mat <- rbind(class1, class2, class3, class4) mat[order(rowMeans(mat), decreasing=TRUE), ] [,1] [,2] [,3] [,4] [,5] class3 2 3 1 4 5 class1 1 3 4 -2 0 class2 2 0 0 -3 0 class4 -4 -5 1 0 0 If the importance of the features is not equal, one can use weigted mean. For example, as follows. w <- c(1, 1, 4, 1, 1) weightedMean <- (mat %*% w)/sum(w) mat[order(weightedMean, decreasing=TRUE), ] [,1] [,2] [,3] [,4] [,5] class1 1 3 4 -2 0 class3 2 3 1 4 5 class2 2 0 0 -3 0 class4 -4 -5 1 0 0 Hope this helps. Petr Savicky.