@ Override public DataSet sample ( int numSamples , org . nd4j . linalg . api . rng . Random rng , boolean withReplacement ) { INDArray examples = Nd4j . create ( numSamples , getFeatures ( ) . columns ( ) ) ; INDArray outcomes = Nd4j . create ( numSamples , numOutcomes ( ) ) ; Set < Integer > added = new HashSet <> ( ) ; for ( int i = 0 ; i < numSamples ; i ++ ) { int picked = rng . nextInt ( numExamples ( ) ) ; if ( ! withReplacement ) while ( added . contains ( picked ) ) picked = rng . nextInt ( numExamples ( ) ) ; examples . putRow ( i , get ( picked ) . getFeatures ( ) ) ; outcomes . putRow ( i , get ( picked ) . getLabels ( ) ) ; } return new DataSet ( examples , outcomes ) ; }
Sample a dataset