public static SingleCSVRecord fromRow ( DataSet row ) { if ( ! row . getFeatures ( ) . isVector ( ) && ! row . getFeatures ( ) . isScalar ( ) ) throw new IllegalArgumentException ( "Passed in dataset must represent a scalar or vector" ) ; if ( ! row . getLabels ( ) . isVector ( ) && ! row . getLabels ( ) . isScalar ( ) ) throw new IllegalArgumentException ( "Passed in dataset labels must be a scalar or vector" ) ; //classification SingleCSVRecord record ; int idx = 0 ; if ( row . getLabels ( ) . sumNumber ( ) . doubleValue ( ) == 1.0 ) { String [ ] values = new String [ row . getFeatures ( ) . columns ( ) + 1 ] ; for ( int i = 0 ; i < row . getFeatures ( ) . length ( ) ; i ++ ) { values [ idx ++ ] = String . valueOf ( row . getFeatures ( ) . getDouble ( i ) ) ; } int maxIdx = 0 ; for ( int i = 0 ; i < row . getLabels ( ) . length ( ) ; i ++ ) { if ( row . getLabels ( ) . getDouble ( maxIdx ) < row . getLabels ( ) . getDouble ( i ) ) { maxIdx = i ; } } values [ idx ++ ] = String . valueOf ( maxIdx ) ; record = new SingleCSVRecord ( values ) ; } //regression (any number of values) else { String [ ] values = new String [ row . getFeatures ( ) . columns ( ) + row . getLabels ( ) . columns ( ) ] ; for ( int i = 0 ; i < row . getFeatures ( ) . length ( ) ; i ++ ) { values [ idx ++ ] = String . valueOf ( row . getFeatures ( ) . getDouble ( i ) ) ; } for ( int i = 0 ; i < row . getLabels ( ) . length ( ) ; i ++ ) { values [ idx ++ ] = String . valueOf ( row . getLabels ( ) . getDouble ( i ) ) ; } record = new SingleCSVRecord ( values ) ; } return record ; }
Instantiate a csv record from a vector given either an input dataset and a one hot matrix the index will be appended to the end of the record or for regression it will append all values in the labels