public EvaluationMetrics evaluate(final String splitPath, final String strategyModelPath) throws IOException {

      EvaluationMetrics results = new EvaluationMetrics();
      double rmseResult = 0.0;
      double maeResult = 0.0;

      for (int cutoff : this.cutoffs) {
         double ndcgRes = 0.0;
         double precisionRes = 0.0;
         double recallRes = 0.0;

         for (int i = 0; i < this.numFolds; i++) {
            File testFile = new File(Paths.get(splitPath, "test_" + i + FILE_EXT).toString());
            File strategyFile = new File(Paths.get(strategyModelPath, "strategymodel_" + i + FILE_EXT).toString());
            DataModelIF<Long, Long> testModel = new SimpleParser().parseData(testFile);
            DataModelIF<Long, Long> strategyModel = new SimpleParser().parseData(strategyFile);

            // Error metrics calculated only once per fold, using all predictions
            if (cutoff == this.cutoffs[0]) {
               RMSE<Long, Long> rmse = new RMSE<>(strategyModel, testModel);
               rmse.compute();
               rmseResult += rmse.getValue();

               MAE<Long, Long> mae = new MAE<>(strategyModel, testModel);
               mae.compute();
               maeResult += mae.getValue();
            }

            // Ranking metrics
            NDCG<Long, Long> ndcg = new NDCG<>(strategyModel, testModel, new int[]{cutoff});
            ndcg.compute();
            ndcgRes += ndcg.getValueAt(cutoff);

            Precision<Long, Long> precision = new Precision<>(strategyModel, testModel, this.relevanceThreshold, new int[]{cutoff});
            precision.compute();
            precisionRes += precision.getValueAt(cutoff);

            Recall<Long, Long> recall = new Recall<>(strategyModel, testModel, this.relevanceThreshold, new int[]{cutoff});
            recall.compute();
            recallRes += recall.getValueAt(cutoff);
         }

         results.setPrecisionAtK(cutoff, precisionRes / this.numFolds);
         results.setRecallAtK(cutoff, recallRes / this.numFolds);
         results.setNDCGAtK(cutoff, ndcgRes / this.numFolds);

         log.info("Ranking metrics at {} computed", cutoff);
         log.info("NDCG@" + cutoff + ": " + ndcgRes / this.numFolds + " / P@" + cutoff + ": " + precisionRes / this.numFolds
                 + " / R@" + cutoff + ": " + recallRes / this.numFolds);

      }

      results.setMAE(maeResult / this.numFolds);
      results.setRMSE(rmseResult / this.numFolds);
      log.info("Error metrics computed");
      log.info("RMSE: " + rmseResult / this.numFolds + " / MAE: " + maeResult / this.numFolds);

      return results;
   }
public EvaluationMetrics evaluate ( final String splitPath , final String strategyModelPath ) throws IOException { EvaluationMetrics results = new EvaluationMetrics ( ) ; double rmseResult = 0.0 ; double maeResult = 0.0 ; for ( int cutoff : this . cutoffs ) { double ndcgRes = 0.0 ; double precisionRes = 0.0 ; double recallRes = 0.0 ; for ( int i = 0 ; i < this . numFolds ; i ++ ) { File testFile = new File ( Paths . get ( splitPath , "test_" + i + FILE_EXT ) . toString ( ) ) ; File strategyFile = new File ( Paths . get ( strategyModelPath , "strategymodel_" + i + FILE_EXT ) . toString ( ) ) ; DataModelIF < Long , Long > testModel = new SimpleParser ( ) . parseData ( testFile ) ; DataModelIF < Long , Long > strategyModel = new SimpleParser ( ) . parseData ( strategyFile ) ; if ( cutoff == this . cutoffs [ 0 ] ) { RMSE < Long , Long > rmse = new RMSE < > ( strategyModel , testModel ) ; rmse . compute ( ) ; rmseResult += rmse . getValue ( ) ; MAE < Long , Long > mae = new MAE < > ( strategyModel , testModel ) ; mae . compute ( ) ; maeResult += mae . getValue ( ) ; } NDCG < Long , Long > ndcg = new NDCG < > ( strategyModel , testModel , new int [ ] { cutoff } ) ; ndcg . compute ( ) ; ndcgRes += ndcg . getValueAt ( cutoff ) ; Precision < Long , Long > precision = new Precision < > ( strategyModel , testModel , this . relevanceThreshold , new int [ ] { cutoff } ) ; precision . compute ( ) ; precisionRes += precision . getValueAt ( cutoff ) ; Recall < Long , Long > recall = new Recall < > ( strategyModel , testModel , this . relevanceThreshold , new int [ ] { cutoff } ) ; recall . compute ( ) ; recallRes += recall . getValueAt ( cutoff ) ; } results . setPrecisionAtK ( cutoff , precisionRes / this . numFolds ) ; results . setRecallAtK ( cutoff , recallRes / this . numFolds ) ; results . setNDCGAtK ( cutoff , ndcgRes / this . numFolds ) ; log . info ( "Ranking metrics at {} computed" , cutoff ) ; log . info ( "NDCG@" + cutoff + ": " + ndcgRes / this . numFolds + " / P@" + cutoff + ": " + precisionRes / this . numFolds + " / R@" + cutoff + ": " + recallRes / this . numFolds ) ; } results . setMAE ( maeResult / this . numFolds ) ; results . setRMSE ( rmseResult / this . numFolds ) ; log . info ( "Error metrics computed" ) ; log . info ( "RMSE: " + rmseResult / this . numFolds + " / MAE: " + maeResult / this . numFolds ) ; return results ; }
Evaluate predictions using an evaluation model against the test set.

@param splitPath         path where splits have been stored
@param strategyModelPath path where strategy model files have been stored
@return evaluation metrics