code: public double validate() {
          // remove a potential duplicate LanguageProfile
          this.removeLanguageProfile(this.languageProfileBuilder.build().getLocale().getLanguage());
  
          List<TextObject> partitionedInput = partition();
          List<Double> probabilities = new ArrayList<>(this.k);
  
          System.out.println("------------------- Running " + this.k + "-fold cross-validation -------------------");
  
          for (int i = 0; i < this.k; i++) {
              System.out.println(" ----------------- Run " + (i + 1) + " -------------------");
              LanguageProfileBuilder lpb = new LanguageProfileBuilder(this.languageProfileBuilder);
              TextObject testSample = partitionedInput.get(i);
  
              List<TextObject> trainingSamples = new ArrayList<>(partitionedInput);
              trainingSamples.remove(i);
              for (TextObject token : trainingSamples) {
                  lpb.addText(token);
              }
              final LanguageProfile languageProfile = lpb.build();
  
              this.languageProfiles.add(languageProfile);
  
              final LanguageDetector languageDetector = LanguageDetectorBuilder.create(NgramExtractors.standard())
                      .withProfiles(this.languageProfiles)
                      .build();
  
              // remove the newly created LanguageProfile for the next round
              this.languageProfiles.remove(this.languageProfiles.size() - 1);
  
              List<DetectedLanguage> detectedLanguages = languageDetector.getProbabilities(testSample);
  
              try{
                  DetectedLanguage kResult = Iterables.find(detectedLanguages, new Predicate<DetectedLanguage>() {
                      public boolean apply(DetectedLanguage language) {
                          return language.getLocale().getLanguage().equals(languageProfile.getLocale().getLanguage());
                      }
                  });
  
                  probabilities.add(kResult.getProbability());
                  System.out.println("Probability: " + kResult.getProbability());
  
              }catch (NoSuchElementException e){
                  System.out.println("No match. Probability: 0");
                  probabilities.add(0D);
              }
          }
  
          double sum = 0D;
          for (Double token : probabilities) {
              sum += token;
          }
          double avg = sum / this.k;
  
          System.out.println("The average probability over all runs is: " + avg);
  
          return avg;
      }
docs: Run the n-fold validation.
  @return the average probability over all runs.