src/main/java/ch/uzh/ifi/seal/ase/cscc/RecommenderHelper.java
public void performTenFoldCrossValidation() {
        List<String> zips = IoHelper.findAllZips(contextsDir);
        int zipsTotal = getNumZips(zips);

        float[] precisions = new float[10];
        float[] recalls = new float[10];

        // let's just divide the zips in 10 buckets, naively assuming they all contain about the
        // same number of contexts
        int bucketSize = zipsTotal / 10;

        // for each bucket, train a model and evaluate it
        for (int i = 1; i <= 10; i++) {
            // Use the InMemoryInvertedIndex for cross-validation, otherwise we will interfere with a possibly already trained
            // model from a DiskBasedInvertedIndex. If you want to use a DiskBasedInvertedIndex (e.g. because of memory
            // limitations), you would have to make sure that each bucket is trained in a different folder (or that
            // after each bucket you delete the previously trained model).
            CompletionModel completionModel = new CompletionModel(new InMemoryInvertedIndex());

            System.out.printf("training model %d/%d\n", i, 10);
            modelFromTrainingBuckets(bucketSize, i, completionModel);

            System.out.printf("evaluating model %d/%d\n", i, 10);
            float[] result = performCrossValidation(bucketSize, i, completionModel);
            precisions[i - 1] = result[0];
            recalls[i - 1] = result[1];
        }
        System.out.printf("-------------------------------\n" +
                "overall 10-fold precision = %.0f%%\n" +
                "overall 10-fold recall = %.0f%%\n" +
                "-------------------------------\n", calculateAverage(precisions), calculateAverage(recalls));
    }
/**
     * Perform 10-fold cross-validation on the Contexts data set.
     * Test results are printed to the console.
     */
Perform 10-fold cross-validation on the Contexts data set.
Test results are printed to the console.
Perform 10 - fold cross - validation on the Contexts data set . Test results are printed to the console .
public void performTenFoldCrossValidation() {
        List<String> zips = IoHelper.findAllZips(contextsDir);
        int zipsTotal = getNumZips(zips);
        float[] precisions = new float[10];
        float[] recalls = new float[10];
        int bucketSize = zipsTotal / 10;
        for (int i = 1; i <= 10; i++) {
            CompletionModel completionModel = new CompletionModel(new InMemoryInvertedIndex());
            System.out.printf("training model %d/%d\n", i, 10);
            modelFromTrainingBuckets(bucketSize, i, completionModel);
            System.out.printf("evaluating model %d/%d\n", i, 10);
            float[] result = performCrossValidation(bucketSize, i, completionModel);
            precisions[i - 1] = result[0];
            recalls[i - 1] = result[1];
        }
        System.out.printf("-------------------------------\n" +
                "overall 10-fold precision = %.0f%%\n" +
                "overall 10-fold recall = %.0f%%\n" +
                "-------------------------------\n", calculateAverage(precisions), calculateAverage(recalls));
    }
public void performTenFoldCrossValidation ( ) { List < String > zips = IoHelper . findAllZips ( contextsDir ) ; int zipsTotal = getNumZips ( zips ) ; float [ ] precisions = new float [ 10 ] ; float [ ] recalls = new float [ 10 ] ; int bucketSize = zipsTotal / 10 ; for ( int i = 1 ; i <= 10 ; i ++ ) { CompletionModel completionModel = new CompletionModel ( new InMemoryInvertedIndex ( ) ) ; System . out . printf ( "training model %d/%d\n" , i , 10 ) ; modelFromTrainingBuckets ( bucketSize , i , completionModel ) ; System . out . printf ( "evaluating model %d/%d\n" , i , 10 ) ; float [ ] result = performCrossValidation ( bucketSize , i , completionModel ) ; precisions [ i - 1 ] = result [ 0 ] ; recalls [ i - 1 ] = result [ 1 ] ; } System . out . printf ( "-------------------------------\n" + "overall 10-fold precision = %.0f%%\n" + "overall 10-fold recall = %.0f%%\n" + "-------------------------------\n" , calculateAverage ( precisions ) , calculateAverage ( recalls ) ) ; }
Perform 10-fold cross-validation on the Contexts data set.
Perform 10 - fold cross - validation on the Contexts data set .
// let's just divide the zips in 10 buckets, naively assuming they all contain about the
 // same number of contexts
 // for each bucket, train a model and evaluate it
 // Use the InMemoryInvertedIndex for cross-validation, otherwise we will interfere with a possibly already trained
 // model from a DiskBasedInvertedIndex. If you want to use a DiskBasedInvertedIndex (e.g. because of memory
 // limitations), you would have to make sure that each bucket is trained in a different folder (or that
 // after each bucket you delete the previously trained model).
