DoubleArrayToLabeledPoint implements Function<double[], LabeledPoint> { @Override public LabeledPoint call(double[] tokens) { double response = tokens[tokens.length - 1]; double[] features = new double[tokens.length - 1]; for (int i = 0; i < tokens.length - 1; i++) { features[i] = tokens[i]; } return new LabeledPoint(response, Vectors.dense(features)); } private  DoubleArrayToLabeledPoint(); @Override LabeledPoint call(double[] tokens);  }
@Test public void testTransformation() { DoubleArrayToLabeledPoint doubleArrayToLabeledPoint = new DoubleArrayToLabeledPoint.Builder().build(); LabeledPoint labeledPoint = doubleArrayToLabeledPoint.call(new double[] { 1.1, 2.0, 2.1, 3.4, 0 }); Assert.assertNotNull(labeledPoint); Assert.assertEquals(labeledPoint.label(), 0.0); Assert.assertEquals(labeledPoint.features(), Vectors.dense(new double[] { 1.1, 2.0, 2.1, 3.4 })); }