]> granicus.if.org Git - liblinear/commitdiff
Let nr_fold = l when nr_fold > l in CV
authorleepei <r00922098@csie.ntu.edu.tw>
Sun, 10 Feb 2013 17:39:46 +0000 (01:39 +0800)
committerPo-Wei Wang <xflash96@gmail.com>
Mon, 11 Feb 2013 17:08:04 +0000 (01:08 +0800)
Signed-off-by: Po-Wei Wang <xflash96@gmail.com>
linear.cpp

index 1dc8056f156af1a120305908c1b98aba3eab22bc..6fade58b12c46e4822000937d36ae06347749213 100644 (file)
@@ -2409,10 +2409,15 @@ model* train(const problem *prob, const parameter *param)
 void cross_validation(const problem *prob, const parameter *param, int nr_fold, double *target)
 {
        int i;
-       int *fold_start = Malloc(int,nr_fold+1);
+       int *fold_start;
        int l = prob->l;
        int *perm = Malloc(int,l);
-
+       if (nr_fold > l)
+       {
+               nr_fold = l;
+               fprintf(stderr,"WARNING: # folds > # data. Will use # folds = # data instead (i.e., leave-one-out cross validation)\n");
+       }
+       fold_start = Malloc(int,nr_fold+1);
        for(i=0;i<l;i++) perm[i]=i;
        for(i=0;i<l;i++)
        {