From: Tzu-Ming Kuo Date: Mon, 1 Jul 2013 15:57:43 +0000 (+0800) Subject: Modify function group_classes in linear.cpp to ensure label[0] = 1 if class labels... X-Git-Tag: v194~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a932c3fe99fe03a69197dcd0c89df1e6fa86cc24;p=liblinear Modify function group_classes in linear.cpp to ensure label[0] = 1 if class labels are +1 and -1 --- diff --git a/linear.cpp b/linear.cpp index 6fade58..77237dd 100644 --- a/linear.cpp +++ b/linear.cpp @@ -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