Class CrossValidationPartitioner<E>
java.lang.Object
opennlp.tools.util.eval.CrossValidationPartitioner<E>
Provides access to training and test partitions for n-fold cross validation.
Cross validation is used to evaluate the performance of a classifier when only
training data is available. The training set is split into n parts
and the training / evaluation is performed n times on these parts.
The training partition always consists of n - 1 parts and one part is used for testing.
To use the CrossValidationPartitioner a client iterates over the n
stream. Each CrossValidationPartitioner.TrainingSampleStream represents
one partition and is used first for training and afterwards for testing.
The CrossValidationPartitioner.TestSampleStream can be obtained via the
CrossValidationPartitioner.TrainingSampleStream.getTestSampleStream() method.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classTheCrossValidationPartitioner.TestSampleStreamiterates over all test elements.static classTheCrossValidationPartitioner.TrainingSampleStreamwhich iterates over all training elements. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe last handed outCrossValidationPartitioner.TrainingSampleStream.private final intThe number of parts the data is divided into.private final ObjectStream<E> Anstreamover the whole set of data samples which are used for the cross validation.private intThe index of test part. -
Constructor Summary
ConstructorsConstructorDescriptionCrossValidationPartitioner(Collection<E> elements, int numberOfPartitions) InitializesCrossValidationPartitionerinstance.CrossValidationPartitioner(ObjectStream<E> inElements, int numberOfPartitions) InitializesCrossValidationPartitionerinstance. -
Method Summary
-
Field Details
-
sampleStream
Anstreamover the whole set of data samples which are used for the cross validation. -
numberOfPartitions
private final int numberOfPartitionsThe number of parts the data is divided into. -
testIndex
private int testIndexThe index of test part. -
lastTrainingSampleStream
The last handed outCrossValidationPartitioner.TrainingSampleStream. The reference is needed to poison the instance to fail fast if it is used despite the fact that it is forbidden!.
-
-
Constructor Details
-
CrossValidationPartitioner
InitializesCrossValidationPartitionerinstance.- Parameters:
inElements- TheObjectStream<E>that provides the elements.numberOfPartitions- The number of partitions. Must be greater than0.
-
CrossValidationPartitioner
InitializesCrossValidationPartitionerinstance.- Parameters:
elements- ACollection<E>that provides the elements.numberOfPartitions- The number of partitions. Must be greater than0.
-
-
Method Details
-
hasNext
public boolean hasNext()Checks if there are more partitions available. -
next
Retrieves the next training and test partitions.- Throws:
IOException
-
toString
-