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));
}
Aggregations