Ignore:
Timestamp:
05/03/16 10:30:09 (9 years ago)
Author:
sherbold
Message:
  • added the concept of result storages to the framework and implemented a very simple first prototype of a MySQLResultStorage (that currently only works with a locally running database)
Location:
trunk/CrossPare/src/de/ugoe/cs/cpdp/eval
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/AbstractWekaEvaluation.java

    r63 r68  
    1919import java.io.PrintWriter; 
    2020import java.util.ArrayList; 
     21import java.util.Iterator; 
    2122import java.util.LinkedList; 
    2223import java.util.List; 
     
    4344 * <li>fscore</li> 
    4445 * <li>gscore</li> 
     46 * <li>MCC</li> 
    4547 * <li>AUC</li> 
    4648 * <li>AUCEC (weighted by LOC, if applicable; 0.0 if LOC not available)</li> 
    4749 * <li>tpr: true positive rate</li> 
    4850 * <li>tnr: true negative rate</li> 
     51 * <li>fpr: false positive rate</li> 
     52 * <li>fnr: false negative rate</li> 
    4953 * <li>tp: true positives</li> 
    5054 * <li>fp: false positives</li> 
    5155 * <li>tn: true negatives</li> 
    5256 * <li>fn: false negatives</li> 
    53  * <li>errortrain: training error</li> 
    54  * <li>recalltrain: training recall</li> 
    55  * <li>precisiontrain: training precision</li> 
    56  * <li>succHetrain: training success with recall>0.7 and precision>0.5 
    5757 * </ul> 
    5858 *  
     
    6767 
    6868    private boolean outputIsSystemOut = true; 
     69     
     70    private String configurationName = "default"; 
    6971 
    7072    /** 
    71      * Creates the weka evaluator. Allows the creation of the evaluator in different ways, e.g., for 
     73     * Creates the Weka evaluator. Allows the creation of the evaluator in different ways, e.g., for 
    7274     * cross-validation or evaluation on the test data. 
    7375     *  
     
    9092                      Instances traindata, 
    9193                      List<ITrainer> trainers, 
    92                       boolean writeHeader) 
     94                      boolean writeHeader, 
     95                      List<IResultStorage> storages) 
    9396    { 
    94         final List<Classifier> classifiers = new LinkedList<Classifier>(); 
     97        final List<Classifier> classifiers = new LinkedList<>(); 
     98        final List<ExperimentResult> experimentResults = new LinkedList<>(); 
     99        String productName = testdata.relationName(); 
     100         
    95101        for (ITrainer trainer : trainers) { 
    96102            if (trainer instanceof IWekaCompatibleTrainer) { 
    97103                classifiers.add(((IWekaCompatibleTrainer) trainer).getClassifier()); 
     104                experimentResults.add(new ExperimentResult(configurationName, productName, ((IWekaCompatibleTrainer) trainer).getName())); 
    98105            } 
    99106            else { 
     
    129136        } 
    130137 
    131         output.append(testdata.relationName()); 
     138        output.append(productName); 
    132139        output.append("," + testdata.numInstances()); 
    133140        output.append("," + traindata.numInstances()); 
    134141 
    135142        Evaluation eval = null; 
    136         //Evaluation evalTrain = null; 
    137         for (Classifier classifier : classifiers) { 
     143        Iterator<Classifier> classifierIter = classifiers.iterator(); 
     144        Iterator<ExperimentResult> resultIter = experimentResults.iterator(); 
     145        while (classifierIter.hasNext()) { 
     146            Classifier classifier = classifierIter.next(); 
    138147            eval = createEvaluator(testdata, classifier); 
    139             //evalTrain = createEvaluator(traindata, classifier); 
    140148 
    141149            double pf = 
     
    143151            double gmeasure = 2 * eval.recall(1) * (1.0 - pf) / (eval.recall(1) + (1.0 - pf)); 
    144152            double aucec = calculateReviewEffort(testdata, classifier); 
    145  
    146             if (eval.recall(1) >= 0.7 && eval.precision(1) >= 0.5) { 
    147                 output.append(",1"); 
    148             } 
    149             else { 
    150                 output.append(",0"); 
    151             } 
    152  
    153             if (eval.recall(1) >= 0.7 && eval.precision(1) >= 0.7) { 
    154                 output.append(",1"); 
    155             } 
    156             else { 
    157                 output.append(",0"); 
    158             } 
    159  
    160             if (gmeasure > 0.75) { 
    161                 output.append(",1"); 
    162             } 
    163             else { 
    164                 output.append(",0"); 
    165             } 
    166  
    167             if (gmeasure > 0.6) { 
    168                 output.append(",1"); 
    169             } 
    170             else { 
    171                 output.append(",0"); 
    172             } 
    173  
     153            double succHe = eval.recall(1) >= 0.7 && eval.precision(1) >= 0.5 ? 1.0 : 0.0; 
     154            double succZi = eval.recall(1) >= 0.7 && eval.precision(1) >= 0.7 ? 1.0 : 0.0; 
     155            double succG75 = gmeasure > 0.75 ? 1.0 : 0.0; 
     156            double succG60 = gmeasure > 0.6 ? 1.0 : 0.0; 
     157             
     158            output.append("," + succHe); 
     159            output.append("," + succZi); 
     160            output.append("," + succG75); 
     161            output.append("," + succG60);             
    174162            output.append("," + eval.errorRate()); 
    175163            output.append("," + eval.recall(1)); 
     
    188176            output.append("," + eval.numTrueNegatives(1)); 
    189177            output.append("," + eval.numFalsePositives(1)); 
     178             
     179            ExperimentResult result = resultIter.next(); 
     180            result.setSizeTestData(testdata.numInstances()); 
     181            result.setSizeTrainingData(traindata.numInstances()); 
     182            result.setSuccHe(succHe); 
     183            result.setSuccZi(succZi); 
     184            result.setSuccG75(succG75); 
     185            result.setSuccG60(succG60); 
     186            result.setError(eval.errorRate()); 
     187            result.setRecall(eval.recall(1)); 
     188            result.setPrecision(eval.precision(1)); 
     189            result.setFscore(eval.fMeasure(1)); 
     190            result.setGscore(gmeasure); 
     191            result.setMcc(eval.matthewsCorrelationCoefficient(1)); 
     192            result.setAuc(eval.areaUnderROC(1)); 
     193            result.setAucec(aucec); 
     194            result.setTpr(eval.truePositiveRate(1)); 
     195            result.setTnr(eval.trueNegativeRate(1)); 
     196            result.setFpr(eval.falsePositiveRate(1)); 
     197            result.setFnr(eval.falseNegativeRate(1)); 
     198            result.setTp(eval.numTruePositives(1)); 
     199            result.setFn(eval.numFalseNegatives(1)); 
     200            result.setTn(eval.numTrueNegatives(1)); 
     201            result.setFp(eval.numFalsePositives(1)); 
     202            for( IResultStorage storage : storages ) { 
     203                storage.addResult(result); 
     204            } 
    190205        } 
    191206 
     
    301316                output = new PrintWriter(new FileOutputStream(parameters)); 
    302317                outputIsSystemOut = false; 
     318                int filenameStart = parameters.lastIndexOf('/')+1; 
     319                int filenameEnd = parameters.lastIndexOf('.'); 
     320                configurationName = parameters.substring(filenameStart, filenameEnd); 
    303321            } 
    304322            catch (FileNotFoundException e) { 
  • trunk/CrossPare/src/de/ugoe/cs/cpdp/eval/IEvaluationStrategy.java

    r41 r68  
    4040     * @param writeHeader 
    4141     *            if true, a header line for the results file is written (may not be applicable) 
     42     * @param storages 
     43     *            result storages that shall additionally be used 
    4244     */ 
    43     void apply(Instances testdata, Instances traindata, List<ITrainer> trainers, boolean writeHeader); 
     45    void apply(Instances testdata, 
     46               Instances traindata, 
     47               List<ITrainer> trainers, 
     48               boolean writeHeader, 
     49               List<IResultStorage> storages); 
    4450} 
Note: See TracChangeset for help on using the changeset viewer.