DataType
- The type of data to create the folds for.public class CrossFoldCreator<DataType> extends AbstractRandomized implements ValidationFoldCreator<DataType,DataType>
CrossFoldCreator
implements a validation fold creator that
creates folds for a typical k-fold cross-validation experiment. That is, it
splits the data into k folds where each item appears in the testing set in
exactly 1 fold and in the training set in the remaining k - 1 folds. At the
limit where k is equal to the size of the data, this becomes leave-one-out
cross-validation, but is typically used in the case where leave-one-out
cross-validation is too costly to run and k is set to a much smaller value.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_NUM_FOLDS
The default number of folds is 10.
|
protected int |
numFolds
The number of folds to create.
|
random
Constructor and Description |
---|
CrossFoldCreator()
Creates a new instance of CrossFoldCreator with a default number of folds
(10) and a default Random number generator.
|
CrossFoldCreator(int numFolds)
Creates a new CrossFoldCreator.
|
CrossFoldCreator(int numFolds,
java.util.Random random)
Creates a new CrossFoldCreator.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
checkNumFolds(int numFolds)
Checks the given number of folds to make sure that it is greater than
1.
|
java.util.List<PartitionedDataset<DataType>> |
createFolds(java.util.Collection<? extends DataType> data)
Creates the requested number of cross-validation folds from the given
data.
|
static <DataType> java.util.List<PartitionedDataset<DataType>> |
createFolds(java.util.Collection<? extends DataType> data,
int numFolds,
java.util.Random random)
Creates the requested number of cross-validation folds from the given
data.
|
int |
getNumFolds()
Gets the number of folds to create.
|
void |
setNumFolds(int numFolds)
Sets the number of folds to create.
|
clone, getRandom, setRandom
public static final int DEFAULT_NUM_FOLDS
protected int numFolds
public CrossFoldCreator()
public CrossFoldCreator(int numFolds)
numFolds
- The number of folds to create.public CrossFoldCreator(int numFolds, java.util.Random random)
numFolds
- The number of folds to create.random
- The random number generator to use.public java.util.List<PartitionedDataset<DataType>> createFolds(java.util.Collection<? extends DataType> data)
createFolds
in interface ValidationFoldCreator<DataType,DataType>
data
- The data to create the folds for.public static <DataType> java.util.List<PartitionedDataset<DataType>> createFolds(java.util.Collection<? extends DataType> data, int numFolds, java.util.Random random)
DataType
- The type of data to create folds over.data
- The data to create the folds for.numFolds
- The number of folds to create.random
- The random number generator to use.public int getNumFolds()
public void setNumFolds(int numFolds)
numFolds
- The number of folds to create.protected static void checkNumFolds(int numFolds)
numFolds
- The number of folds.