28.05.2010  pavel

How to quickly rename classes or define meta-classes?

imageWhen designing classifiers, we often need to define new classes by renaming existing ones. sdrelab command allows us to do just that quickly and easily.
Class relabeling helps us to define meta-classes, to compare data sets before and after normalization or to understand where the data of a specific sub-class/patient/cluster fits with respect to others.


Let us say, we have a data set with handwritten digits and wish to train a classifier separating even and odd digits. To quickly list classes present we use the transpose operator to labels:

>> a
2000 by 256 sddata, 10 classes: [200  200  200  200  200  200  200  200  200  200]

>> a.lab'
 ind name size percentage
   1 0     200 (10.0%)
   2 1     200 (10.0%)
   3 2     200 (10.0%)
   4 3     200 (10.0%)
   5 4     200 (10.0%)
   6 5     200 (10.0%)
   7 6     200 (10.0%)
   8 7     200 (10.0%)
   9 8     200 (10.0%)
  10 9     200 (10.0%)

We may rename classes specified by indices the the label list. In our example, the classes 1,3,5 etc. are even. sdrelab command takes a data set or label object to rename and the cell array with rules. Each rule specifies source (what to rename) and destination (into which class). Relabeling of even digits may look like:

>> b=sdrelab(a,{1:2:10,'even'})
  1: 0      -> even
  2: 1      -> 1
  3: 2      -> even
  4: 3      -> 3
  5: 4      -> even
  6: 5      -> 5
  7: 6      -> even
  8: 7      -> 7
  9: 8      -> even
 10: 9      -> 9
2000 by 256 sddata, 6 classes: [200   200   200   200   200  1000]

We may handle the odd digits also by their indices but there is an easier way. We ma simply include additional rule saying that what is not ‘even’ becomes ‘odd’. This negation is specified by the tilde character:

>> b=sdrelab(a,{1:2:10,'even','~even','odd'})
  1: 0      -> even
  2: 1      -> odd 
  3: 2      -> even
  4: 3      -> odd 
  5: 4      -> even
  6: 5      -> odd 
  7: 6      -> even
  8: 7      -> odd 
  9: 8      -> even
 10: 9      -> odd 
2000 by 256 sddata, 2 classes: 'even'(1000) 'odd'(1000)

How not to loose the original labels

As you may see, the data set b now contains only classes ‘even’ and ‘odd’ that replace our original digit labels. How can we preserve the digit labels and add a new set with ‘even’/’odd’ meta-classes?

We invoked sdrelab on a data set a. In this case, sdrelab operates on the current labels a.lab and returns an updated data set back. If we provide it with a label object, it will returned the renamed labels. We may, therefore, process the a.lab labels and store the output in the new set of labels (for example called a.newlab):

>> a.newlab=sdrelab(a.lab,{1:2:10,'even','~even','odd'})
  1: 0      -> even
  2: 1      -> odd 
  3: 2      -> even
  4: 3      -> odd 
  5: 4      -> even
  6: 5      -> odd 
  7: 6      -> even
  8: 7      -> odd 
  9: 8      -> even
 10: 9      -> odd 
2000 by 256 sddata, 10 classes: [200  200  200  200  200  200  200  200  200  200]

>> a.newlab
sdlab with 2000 entries, 2 groups: 'even'(1000) 'odd'(1000) 

>> a'
2000 by 256 sddata, 10 classes: [200  200  200  200  200  200  200  200  200  200]
sample props: 'lab'->'class' 'class'(L) 'ident'(N) 'newlab'(L)
feature props: 'featlab'->'featname' 'featname'(L)
data props:  'data'(N)

Comments

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?

Submit the word you see below: