This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

implementing 10 cross validation (10CV)  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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: 9997
208
  • Mark post as helpful
  • send pies
  • 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: 17
    • Mark post as helpful
    • send pies
    • 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
    }]

     
    Something must be done about this. Let's start by reading this tiny ad:
    global solutions you can do in your home or backyard
    https://coderanch.com/t/708587/global-solutions-home-backyard
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!