Package opennlp.tools.util.eval
Class CrossValidationPartitioner<E>
- java.lang.Object
-
- opennlp.tools.util.eval.CrossValidationPartitioner<E>
-
public class CrossValidationPartitioner<E> extends Object
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 ofn - 1
parts and one part is used for testing.To use the
CrossValidationPartitioner
a client iterates over the nstream
. EachCrossValidationPartitioner.TrainingSampleStream
represents one partition and is used first for training and afterwards for testing. TheCrossValidationPartitioner.TestSampleStream
can be obtained via theCrossValidationPartitioner.TrainingSampleStream.getTestSampleStream()
method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CrossValidationPartitioner.TrainingSampleStream<E>
TheCrossValidationPartitioner.TrainingSampleStream
which iterates over all training elements.
-
Constructor Summary
Constructors Constructor Description CrossValidationPartitioner(Collection<E> elements, int numberOfPartitions)
InitializesCrossValidationPartitioner
instance.CrossValidationPartitioner(ObjectStream<E> inElements, int numberOfPartitions)
InitializesCrossValidationPartitioner
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Checks if there are more partitions available.CrossValidationPartitioner.TrainingSampleStream<E>
next()
Retrieves the next training and test partitions.String
toString()
-
-
-
Constructor Detail
-
CrossValidationPartitioner
public CrossValidationPartitioner(ObjectStream<E> inElements, int numberOfPartitions)
InitializesCrossValidationPartitioner
instance.- Parameters:
inElements
- TheObjectStream
that provides the elements.numberOfPartitions
- The number of partitions. Must be greater than0
.
-
CrossValidationPartitioner
public CrossValidationPartitioner(Collection<E> elements, int numberOfPartitions)
InitializesCrossValidationPartitioner
instance.- Parameters:
elements
- ACollection
that provides the elements.numberOfPartitions
- The number of partitions. Must be greater than0
.
-
-
Method Detail
-
hasNext
public boolean hasNext()
Checks if there are more partitions available.
-
next
public CrossValidationPartitioner.TrainingSampleStream<E> next() throws IOException
Retrieves the next training and test partitions.- Throws:
IOException
-
-