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
}]