Search in sources :

Example 26 with Writable

use of org.datavec.api.writable.Writable in project deeplearning4j by deeplearning4j.

the class MLLibUtil method pointOf.

/**
     * Returns a labeled point of the writables
     * where the final item is the point and the rest of the items are
     * features
     * @param writables the writables
     * @return the labeled point
     */
public static LabeledPoint pointOf(Collection<Writable> writables) {
    double[] ret = new double[writables.size() - 1];
    int count = 0;
    double target = 0;
    for (Writable w : writables) {
        if (count < writables.size() - 1)
            ret[count++] = Float.parseFloat(w.toString());
        else
            target = Float.parseFloat(w.toString());
    }
    if (target < 0)
        throw new IllegalStateException("Target must be >= 0");
    return new LabeledPoint(target, Vectors.dense(ret));
}
Also used : Writable(org.datavec.api.writable.Writable) LabeledPoint(org.apache.spark.mllib.regression.LabeledPoint) LabeledPoint(org.apache.spark.mllib.regression.LabeledPoint)

Aggregations

Writable (org.datavec.api.writable.Writable)26 NDArrayWritable (org.datavec.common.data.NDArrayWritable)18 INDArray (org.nd4j.linalg.api.ndarray.INDArray)17 DataSet (org.nd4j.linalg.dataset.DataSet)12 ArrayList (java.util.ArrayList)8 SequenceRecordReader (org.datavec.api.records.reader.SequenceRecordReader)8 List (java.util.List)7 Test (org.junit.Test)7 CollectionSequenceRecordReader (org.datavec.api.records.reader.impl.collection.CollectionSequenceRecordReader)6 DoubleWritable (org.datavec.api.writable.DoubleWritable)6 IntWritable (org.datavec.api.writable.IntWritable)6 CSVSequenceRecordReader (org.datavec.api.records.reader.impl.csv.CSVSequenceRecordReader)5 Record (org.datavec.api.records.Record)3 RecordMetaDataComposableMap (org.datavec.api.records.metadata.RecordMetaDataComposableMap)3 SequenceRecordReaderDataSetIterator (org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator)3 DL4JInvalidInputException (org.deeplearning4j.exception.DL4JInvalidInputException)3 File (java.io.File)2 Collection (java.util.Collection)2 WritableConverterException (org.datavec.api.io.converters.WritableConverterException)2 SequenceRecord (org.datavec.api.records.SequenceRecord)2