]> granicus.if.org Git - liblinear/commitdiff
Modify function group_classes in linear.cpp to ensure label[0] = 1 if class labels...
authorTzu-Ming Kuo <b99902073@patty.(none)>
Mon, 1 Jul 2013 15:57:43 +0000 (23:57 +0800)
committerTzu-Ming Kuo <b99902073@patty.(none)>
Mon, 1 Jul 2013 15:57:43 +0000 (23:57 +0800)
linear.cpp

index 6fade58b12c46e4822000937d36ae06347749213..77237ddc7fb5cd6b678a21d7f919832471b4f980 100644 (file)
@@ -2140,6 +2140,24 @@ static void group_classes(const problem *prob, int *nr_class_ret, int **label_re
                }
        }
 
+       //
+       // Labels are ordered by their first occurrence in the training set. 
+       // However, for two-class sets with -1/+1 labels and -1 appears first, 
+       // we swap labels to ensure that internally the binary SVM has positive data corresponding to the +1 instances.
+       //
+       if (nr_class == 2 && label[0] == -1 && label[1] == 1)
+       {
+               swap(label[0],label[1]);
+               swap(count[0],count[1]);
+               for(i=0;i<l;i++)
+               {
+                       if(data_label[i] == 0)
+                               data_label[i] = 1;
+                       else
+                               data_label[i] = 0;
+               }
+       }
+
        int *start = Malloc(int,nr_class);
        start[0] = 0;
        for(i=1;i<nr_class;i++)