def run
      fail_if_invalid

      partitions = Partitioner.subset(documents, k)

      results = partitions.map.with_index do |part, i|
        training_samples = Partitioner.exclude_index(documents, i)

        classifier_instance = classifier.call()

        train(classifier_instance, training_samples)

        # fetch confusion keys
        part.each do |x|
          prediction = classify(classifier_instance, x)
          matrix.store(prediction, fetch_sample_class.call(x))
        end
      end

      matrix
    end
def run
      fail_if_invalid

      partitions = Partitioner.subset(documents, k)

      results = partitions.map.with_index do |part, i|
        training_samples = Partitioner.exclude_index(documents, i)

        classifier_instance = classifier.call()

        train(classifier_instance, training_samples)

        # fetch confusion keys
        part.each do |x|
          prediction = classify(classifier_instance, x)
          matrix.store(prediction, fetch_sample_class.call(x))
        end
      end

      matrix
    end
Performs k-fold cross-validation and returns a confusion matrix.

 The algorithm is as follows (Mitchell, 1997, p147):

   partitions = partition data into k-equal sized subsets (folds)
   for i = 1 -> k:
     T = data \ partitions[i]
     train(T)
     classify(partitions[i])
   output confusion matrix

 @raise [ArgumentError] if the runner is missing required attributes
 @return [ConfusionMatrix]