Esempio n. 1
0
 public void processAlgorithm() {
   List<List<Double>> testData = data.getTestData();
   int testNum = data.getTestNum();
   long begin = System.currentTimeMillis();
   for (int i = 0; i < testNum; i++) {
     List<Double> test = testData.get(i);
     result[i][0] = Arith.convertsToInt(test.get(0));
     result[i][1] = Math.round(Float.parseFloat((knn(data.getTrainData(), test, 3))));
     if (result[i][0] != result[i][1]) {
       ma.setWrong(ma.getWrong() + 1);
     }
   }
   long end = System.currentTimeMillis();
   ma.setTime(begin, end);
   ma.setAccuracyRate(ma.getWrong(), testNum);
   ma.setErrorRate(ma.getWrong(), testNum);
 }
Esempio n. 2
0
 public KNN(Data data) {
   this.data = data;
   result = new int[data.getTestNum()][2];
   data.minMaxDataFormat(data.getTrainData());
   data.minMaxDataFormat(data.getTestData());
 }
Esempio n. 3
0
 /** 设置优先级队列的比较函数,距离越大,优先级越高 */
 public KNN() {
   data = new Data();
   result = new int[data.getTestNum()][2];
   data.minMaxDataFormat(data.getTrainData());
   data.minMaxDataFormat(data.getTestData());
 }