code: public static <T> double cv(int k, ClassifierTrainer<T> trainer, T[] x, int[] y, ClassificationMeasure measure) {
          if (k < 2) {
              throw new IllegalArgumentException("Invalid k for k-fold cross validation: " + k);
          }
          
          int n = x.length;
          int[] predictions = new int[n];
          
          CrossValidation cv = new CrossValidation(n, k);
          for (int i = 0; i < k; i++) {
              T[] trainx = Math.slice(x, cv.train[i]);
              int[] trainy = Math.slice(y, cv.train[i]);
              
              Classifier<T> classifier = trainer.train(trainx, trainy);
  
              for (int j : cv.test[i]) {
                  predictions[j] = classifier.predict(x[j]);
              }
          }
          
          return measure.measure(y, predictions);
      }
docs: Cross validation of a classification model.
  
  @param <T> the data type of input objects.
  @param k k-fold cross validation.
  @param trainer a classifier trainer that is properly parameterized.
  @param x the test data set.
  @param y the test data labels.
  @param measure the performance measure of classification.
  @return the test results with the same size of order of measures