示例#1
0
 @Override
 public void algorithm(HttpServletRequest request) {
   KNN knn0 = new KNN();
   knn0.processAlgorithm();
   request.setAttribute("time", knn0.ma.getTime());
   request.setAttribute("KNNResult", knn0.result);
   request.setAttribute("accuracyRate", knn0.ma.getAccuracyRate());
   request.setAttribute("errorRate", knn0.ma.getErrorRate());
   double avgAccruacyRate = 0, avgErrorRate = 0;
   for (int i = 0; i < 10; i++) {
     KNN knn = new KNN(new Data(i));
     knn.processAlgorithm();
     avgAccruacyRate += knn.ma.getAccuracyRate();
     avgErrorRate += knn.ma.getErrorRate();
   }
   request.setAttribute("avgAccuracyRate", avgAccruacyRate / 10);
   request.setAttribute("avgErrorRate", avgErrorRate / 10);
 }
示例#2
0
  /**
   * Apply the NNSSLGenerator method.
   *
   * @return
   */
  public Pair<PrototypeSet, PrototypeSet> applyAlgorithm() {
    System.out.print("\nThe algorithm SELF TRAINING is starting...\n Computing...\n");

    PrototypeSet labeled;
    PrototypeSet unlabeled;

    labeled =
        new PrototypeSet(
            trainingDataSet.getAllDifferentFromClass(
                this.numberOfClass)); // Selecting labeled prototypes from the training set.
    unlabeled = new PrototypeSet(trainingDataSet.getFromClass(this.numberOfClass));

    PrototypeSet tranductive = new PrototypeSet(this.transductiveDataSet.clone());
    PrototypeSet test = new PrototypeSet(this.testDataSet.clone());

    // We have to return the classification done.
    for (int i = 0; i < this.transductiveDataSet.size(); i++) {
      tranductive
          .get(i)
          .setFirstOutput((labeled.nearestTo(this.transductiveDataSet.get(i))).getOutput(0));
    }

    for (int i = 0; i < this.testDataSet.size(); i++) {
      test.get(i).setFirstOutput((labeled.nearestTo(this.testDataSet.get(i))).getOutput(0));
    }

    // Transductive Accuracy
    System.out.println(
        "AccTrs ="
            + KNN.classficationAccuracy1NN(labeled, this.transductiveDataSet)
                * 100.
                / this.transductiveDataSet.size());

    // test accuracy
    System.out.println(
        "AccTst ="
            + KNN.classficationAccuracy1NN(labeled, this.testDataSet)
                * 100.
                / this.testDataSet.size());

    return new Pair<PrototypeSet, PrototypeSet>(tranductive, test);
  }
示例#3
0
文件: AVG.java 项目: Navieclipse/KEEL
  /**
   * General main for all the prototoype generators Arguments: 0: Filename with the training data
   * set to be condensed. 1: Filename wich will contain the test data set
   *
   * @param args Arguments of the main function.
   */
  public static void main(String[] args) {
    Parameters.setUse("AVG", "");
    Parameters.assertBasicArgs(args);

    PrototypeSet training = PrototypeGenerationAlgorithm.readPrototypeSet(args[0]);
    PrototypeSet test = PrototypeGenerationAlgorithm.readPrototypeSet(args[1]);

    AVG generator = new AVG(training);

    PrototypeSet resultingSet = generator.execute();
    int accuracy1NN = KNN.classficationAccuracy(resultingSet, test);
    generator.showResultsOfAccuracy(Parameters.getFileName(), accuracy1NN, test);
  }