예제 #1
0
  private double getAUC(myDataset data) {
    double auc = 0;
    int totalClasses = 0;
    for (int i = 0; i < this.confusionMatrix.length; i++) {
      if (data.numberInstances(i) > 0) {
        totalClasses++;
        double tp = 1.0 * confusionMatrix[i][i] / data.numberInstances(i);
        // System.err.print("TP["+i+"]: "+tp);
        for (int j = 0; j < this.confusionMatrix[i].length; j++) {
          if ((j != i) && (data.numberInstances(j) > 0)) {
            double fp = 1.0 * this.confusionMatrix[j][i] / data.numberInstances(j);
            // System.err.print(", FP["+j+"]: "+fp);
            double auc_j = (tp - fp + 1) / 2.0;
            // System.err.print(", AUC["+j+"]: "+auc_j);
            auc += auc_j;
          }
        }
      }
      // System.err.println("");
    }

    double tpr = 1.0 * confusionMatrix[0][0] / data.numberInstances(0);
    double fpr = 1.0 * confusionMatrix[1][0] / data.numberInstances(1);
    double auc1 = ((1 + tpr - fpr) / 2.0);

    double auc2 = (auc / (totalClasses * (totalClasses - 1)));
    return auc2;
  }
예제 #2
0
  /** It launches the algorithm */
  public void execute() {
    if (this.somethingWrong) { // We do not execute the program
      System.err.println("An error was found, either the data-set has missing values.");
      System.err.println(
          "Please remove the examples with missing data or apply a MV preprocessing.");
      System.err.println("Aborting the program");
      // We should not use the statement: System.exit(-1);
    } else {
      // We do here the algorithm's operations

      int nClasses = train.getnClasses();
      aprioriClassDistribution = new double[nClasses];
      for (int i = 0; i < nClasses; i++) {
        aprioriClassDistribution[i] = 1.0 * val.numberInstances(i) / val.size();
      }

      if (model) { // el modelo no esta generado en fichero previamente
        NSGA2 search =
            new NSGA2(
                train, seed, populationSize, maxTrials, crossover, mutation, instances, fitness);
        try {
          search.execute();
        } catch (Exception e) {
          e.printStackTrace(System.err);
        }
      }

      // Finally we should fill the training and test output files

      this.generateModel();

      double avgTr = this.doOutput(val, this.outputTr, false);
      double aucTr = getAUC(val);
      double avgTst = this.doOutput(test, this.outputTst, true);
      double aucTst = getAUC(test);
      System.out.print("AUC Train: " + aucTr);
      System.out.println("; AvgAcc Train: " + avgTr);
      System.out.print("AUC Test: " + aucTst);
      System.out.println("; AvgAcc Test: " + avgTst);

      totalTime = System.currentTimeMillis() - startTime;
      System.out.println("Algorithm Finished: " + totalTime);
    }
  }