我正在PSO中进行功能选择。我使用带有10个交叉验证的KNN算法进行评估。在我使用10cv之前,该算法非常便宜,这意味着没有高昂的计算成本,但是转向10cv之后,代码运行速度太慢,有时需要几天。我可以知道执行10cv时是否有任何问题。我使用以下代码执行10个简历:
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
}