Class KFoldIterator
- java.lang.Object
-
- org.nd4j.linalg.dataset.api.iterator.KFoldIterator
-
- All Implemented Interfaces:
Serializable,Iterator<DataSet>,DataSetIterator
public class KFoldIterator extends Object implements DataSetIterator
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DataSetallDataprotected int[]intervalBoundariesprotected intkprotected intkCursorprotected intNprotected DataSetPreProcessorpreProcessorprotected DataSettestprotected DataSettrain
-
Constructor Summary
Constructors Constructor Description KFoldIterator(int k, DataSet allData)Create an iterator given the dataset with given k train-test splits N number of samples are split into k batches.KFoldIterator(DataSet allData)Create a k-fold cross-validation iterator given the dataset and k=10 train-test splits.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanasyncSupported()Does this DataSetIterator support asynchronous prefetching of multiple DataSet objects? Most DataSetIterators do, but in some cases it may not make sense to wrap this iterator in an iterator that does asynchronous prefetching.intbatch()The number of examples in every fold is (N / k), except when (N % k) > 0, when the first (N % k) folds contain (N / k) + 1 examplesList<String>getLabels()Get dataset iterator class labels, if any.DataSetPreProcessorgetPreProcessor()Returns preprocessors, if definedbooleanhasNext()intinputColumns()Input columns for the datasetDataSetnext()DataSetnext(int num)Like the standard next method but allows a customizable number of examples returnedprotected voidnextFold()voidremove()voidreset()Shuffles the dataset and resets to the first foldbooleanresetSupported()Is resetting supported by this DataSetIterator? Many DataSetIterators do support resetting, but some don'tvoidsetPreProcessor(DataSetPreProcessor preProcessor)Set a pre processorDataSettestFold()inttotalExamples()Returns total number of examples in the dataset (all k folds)inttotalOutcomes()The number of labels for the dataset-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
allData
protected DataSet allData
-
k
protected int k
-
N
protected int N
-
intervalBoundaries
protected int[] intervalBoundaries
-
kCursor
protected int kCursor
-
test
protected DataSet test
-
train
protected DataSet train
-
preProcessor
protected DataSetPreProcessor preProcessor
-
-
Constructor Detail
-
KFoldIterator
public KFoldIterator(DataSet allData)
Create a k-fold cross-validation iterator given the dataset and k=10 train-test splits. N number of samples are split into k batches. The first (N%k) batches contain (N/k)+1 samples, while the remaining batches contain (N/k) samples. In case the number of samples (N) in the dataset is a multiple of k, all batches will contain (N/k) samples.- Parameters:
allData- DataSet to split into k folds
-
KFoldIterator
public KFoldIterator(int k, DataSet allData)Create an iterator given the dataset with given k train-test splits N number of samples are split into k batches. The first (N%k) batches contain (N/k)+1 samples, while the remaining batches contain (N/k) samples. In case the number of samples (N) in the dataset is a multiple of k, all batches will contain (N/k) samples.- Parameters:
k- number of folds (optional, defaults to 10)allData- DataSet to split into k folds
-
-
Method Detail
-
next
public DataSet next(int num) throws UnsupportedOperationException
Description copied from interface:DataSetIteratorLike the standard next method but allows a customizable number of examples returned- Specified by:
nextin interfaceDataSetIterator- Parameters:
num- the number of examples- Returns:
- the next data applyTransformToDestination
- Throws:
UnsupportedOperationException
-
totalExamples
public int totalExamples()
Returns total number of examples in the dataset (all k folds)- Returns:
- total number of examples in the dataset including all k folds
-
inputColumns
public int inputColumns()
Description copied from interface:DataSetIteratorInput columns for the dataset- Specified by:
inputColumnsin interfaceDataSetIterator- Returns:
-
totalOutcomes
public int totalOutcomes()
Description copied from interface:DataSetIteratorThe number of labels for the dataset- Specified by:
totalOutcomesin interfaceDataSetIterator- Returns:
-
resetSupported
public boolean resetSupported()
Description copied from interface:DataSetIteratorIs resetting supported by this DataSetIterator? Many DataSetIterators do support resetting, but some don't- Specified by:
resetSupportedin interfaceDataSetIterator- Returns:
- true if reset method is supported; false otherwise
-
asyncSupported
public boolean asyncSupported()
Description copied from interface:DataSetIteratorDoes this DataSetIterator support asynchronous prefetching of multiple DataSet objects? Most DataSetIterators do, but in some cases it may not make sense to wrap this iterator in an iterator that does asynchronous prefetching. For example, it would not make sense to use asynchronous prefetching for the following types of iterators: (a) Iterators that store their full contents in memory already (b) Iterators that re-use features/labels arrays (as future next() calls will overwrite past contents) (c) Iterators that already implement some level of asynchronous prefetching (d) Iterators that may return different data depending on when the next() method is called- Specified by:
asyncSupportedin interfaceDataSetIterator- Returns:
- true if asynchronous prefetching from this iterator is OK; false if asynchronous prefetching should not be used with this iterator
-
reset
public void reset()
Shuffles the dataset and resets to the first fold- Specified by:
resetin interfaceDataSetIterator
-
batch
public int batch()
The number of examples in every fold is (N / k), except when (N % k) > 0, when the first (N % k) folds contain (N / k) + 1 examples- Specified by:
batchin interfaceDataSetIterator- Returns:
- examples in a fold
-
setPreProcessor
public void setPreProcessor(DataSetPreProcessor preProcessor)
Description copied from interface:DataSetIteratorSet a pre processor- Specified by:
setPreProcessorin interfaceDataSetIterator- Parameters:
preProcessor- a pre processor to set
-
getPreProcessor
public DataSetPreProcessor getPreProcessor()
Description copied from interface:DataSetIteratorReturns preprocessors, if defined- Specified by:
getPreProcessorin interfaceDataSetIterator- Returns:
-
getLabels
public List<String> getLabels()
Description copied from interface:DataSetIteratorGet dataset iterator class labels, if any. Note that implementations are not required to implement this, and can simply return null- Specified by:
getLabelsin interfaceDataSetIterator
-
nextFold
protected void nextFold()
-
testFold
public DataSet testFold()
- Returns:
- the held out fold as a dataset
-
-