• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

implementing 10 cross validation (10CV)

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I am working in PSO for feature selection. I use KNN algorithm with 10 cross validation for the evaluation. before I use the 10cv the algorithm is quite cheap meaning no high computational cost has been faced, but after turning to 10cv the code is running too slow, sometimes for days. may I know if there is any problem in performing the 10cv. I use the following code to perform 10 cv:

dataset data = FileHandler.loadDataset(new File(dataSetFileName+".csv"), noFeatures, ",");
               //crossvalidationmat
                 int[][] crossvalidationmat= {
                   {1,2,3,4,5,6,7,8,9},
                   {0,2,3,4,5,6,7,8,9},
                   {0,1,3,4,5,6,7,8,9},
                   {0,1,2,4,5,6,7,8,9},
                   {0,1,2,3,5,6,7,8,9},
                   {0,1,2,3,4,6,7,8,9},
                   {0,1,2,3,4,5,7,8,9},
                   {0,1,2,3,4,5,6,8,9},
                   {0,1,2,3,4,5,6,7,9},
                   {0,1,2,3,4,5,6,7,8},
                   };
       Dataset[] folds = data.folds((10), new Random(1));
       Dataset training = new DefaultDataset();    //training, testing
       Dataset testing = new DefaultDataset();  
       int[] tr =new int[9];
       int[] te = new int[1];
for (int di = 0; di < crossvalidationmat.length; di++) { // start crossvalidation
      System.out.println(crossvalidationmat[di].length);
for (int xj = 0; xj < crossvalidationmat[di].length; xj++) {
        tr[xj]=crossvalidationmat[di][xj];
        System.out.print(tr[xj]);
   }
   te[0]=di;
   System.out.println("\nTraing  te[0]=di here:  "+te[0]);
       for (int i = 0; i < tr.length; i++) {
           training.addAll(folds[tr[i]]);
       }
       for (int i = 0; i < te.length; i++) {
           testing.addAll(folds[te[i]]);
       }
Dataset[] foldsTrain = training.folds(numFolds, new Random(1));
//other code
}
 
Saloon Keeper
Posts: 12825
279
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'll get more help with this if you:

  • Enclose your code in [code]code[/code] tags.
  • Write out acronyms like PSO and KNN. I have no idea what you're talking about.
  • Describe the purpose of the algorithm.
  • Describe the expected output, and what you're getting instead.
  • Describe why you're stuck.
  •  
    arwa ali
    Greenhorn
    Posts: 29
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    arwa ali wrote:


    I am working in particle swarm optimization for feature selection. I use k nearest neighbors  classification algorithm with 10 cross validation for the evaluation. i use the algorithm to achieve feature selection meaning to reduce the number of features , before I use the 10 cross validation the algorithm is quite cheap meaning no high computational cost has been faced, but after turning to 10 cross validation the code is running too slow, sometimes for days. may I know if there is any problem in performing the 10cv. I use the following code to perform 10 cv:

    [dataset data = FileHandler.loadDataset(new File(dataSetFileName+".csv"), noFeatures, ",");
                   //crossvalidationmat
                     int[][] crossvalidationmat= {
                       {1,2,3,4,5,6,7,8,9},
                       {0,2,3,4,5,6,7,8,9},
                       {0,1,3,4,5,6,7,8,9},
                       {0,1,2,4,5,6,7,8,9},
                       {0,1,2,3,5,6,7,8,9},
                       {0,1,2,3,4,6,7,8,9},
                       {0,1,2,3,4,5,7,8,9},
                       {0,1,2,3,4,5,6,8,9},
                       {0,1,2,3,4,5,6,7,9},
                       {0,1,2,3,4,5,6,7,8},
                       };
           Dataset[] folds = data.folds((10), new Random(1));
           Dataset training = new DefaultDataset();    //training, testing
           Dataset testing = new DefaultDataset();  
           int[] tr =new int[9];
           int[] te = new int[1];
    for (int di = 0; di < crossvalidationmat.length; di++) { // start crossvalidation
          System.out.println(crossvalidationmat[di].length);
    for (int xj = 0; xj < crossvalidationmat[di].length; xj++) {
            tr[xj]=crossvalidationmat[di][xj];
            System.out.print(tr[xj]);
       }
       te[0]=di;
       System.out.println("\nTraing  te[0]=di here:  "+te[0]);
           for (int i = 0; i < tr.length; i++) {
               training.addAll(folds[tr[i]]);
           }
           for (int i = 0; i < te.length; i++) {
               testing.addAll(folds[te[i]]);
           }
    Dataset[] foldsTrain = training.folds(numFolds, new Random(1));
    //other code
    }]

     
    This will take every ounce of my mental strength! All for a tiny ad:
    SKIP - a book about connecting industrious people with elderly land owners
    https://coderanch.com/t/skip-book
    reply
      Bookmark Topic Watch Topic
    • New Topic