Java Code Examples for org.datavec.api.util.ndarray.RecordConverter#toRecords()
The following examples show how to use
org.datavec.api.util.ndarray.RecordConverter#toRecords() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecordConverterTest.java From DataVec with Apache License 2.0 | 6 votes |
@Test public void toRecords_PassInRegressionDataSet_ExpectNDArrayAndDoubleWritables() { INDArray feature = Nd4j.create(new double[]{4, -5.7, 10, -0.1}); INDArray label = Nd4j.create(new double[]{.5, 2, 3, .5}); DataSet dataSet = new DataSet(feature, label); List<List<Writable>> writableList = RecordConverter.toRecords(dataSet); List<Writable> results = writableList.get(0); NDArrayWritable ndArrayWritable = (NDArrayWritable) results.get(0); assertEquals(1, writableList.size()); assertEquals(5, results.size()); assertEquals(feature, ndArrayWritable.get()); for (int i = 0; i < label.shape()[1]; i++) { DoubleWritable doubleWritable = (DoubleWritable) results.get(i + 1); assertEquals(label.getDouble(i), doubleWritable.get(), 0); } }
Example 2
Source File: DataFramesTests.java From DataVec with Apache License 2.0 | 6 votes |
@Test public void testMinMax() { INDArray arr = Nd4j.linspace(1, 10, 10).broadcast(10, 10); for (int i = 0; i < arr.rows(); i++) arr.getRow(i).addi(i); List<List<Writable>> records = RecordConverter.toRecords(arr); Schema.Builder builder = new Schema.Builder(); int numColumns = 10; for (int i = 0; i < numColumns; i++) builder.addColumnDouble(String.valueOf(i)); Schema schema = builder.build(); DataRowsFacade dataFrame = DataFrames.toDataFrame(schema, sc.parallelize(records)); dataFrame.get().show(); dataFrame.get().describe(DataFrames.toArray(schema.getColumnNames())).show(); // System.out.println(Normalization.minMaxColumns(dataFrame,schema.getColumnNames())); // System.out.println(Normalization.stdDevMeanColumns(dataFrame,schema.getColumnNames())); }
Example 3
Source File: RecordConverterTest.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void toRecords_PassInRegressionDataSet_ExpectNDArrayAndDoubleWritables() { INDArray feature = Nd4j.create(new double[]{4, -5.7, 10, -0.1}, new long[]{1, 4}, DataType.FLOAT); INDArray label = Nd4j.create(new double[]{.5, 2, 3, .5}, new long[]{1, 4}, DataType.FLOAT); DataSet dataSet = new DataSet(feature, label); List<List<Writable>> writableList = RecordConverter.toRecords(dataSet); List<Writable> results = writableList.get(0); NDArrayWritable ndArrayWritable = (NDArrayWritable) results.get(0); assertEquals(1, writableList.size()); assertEquals(5, results.size()); assertEquals(feature, ndArrayWritable.get()); for (int i = 0; i < label.shape()[1]; i++) { DoubleWritable doubleWritable = (DoubleWritable) results.get(i + 1); assertEquals(label.getDouble(i), doubleWritable.get(), 0); } }
Example 4
Source File: DataFramesTests.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Test public void testMinMax() { INDArray arr = Nd4j.linspace(1, 10, 10).broadcast(10, 10); for (int i = 0; i < arr.rows(); i++) arr.getRow(i).addi(i); List<List<Writable>> records = RecordConverter.toRecords(arr); Schema.Builder builder = new Schema.Builder(); int numColumns = 10; for (int i = 0; i < numColumns; i++) builder.addColumnDouble(String.valueOf(i)); Schema schema = builder.build(); Dataset<Row> dataFrame = DataFrames.toDataFrame(schema, sc.parallelize(records)); dataFrame.show(); dataFrame.describe(DataFrames.toArray(schema.getColumnNames())).show(); // System.out.println(Normalization.minMaxColumns(dataFrame,schema.getColumnNames())); // System.out.println(Normalization.stdDevMeanColumns(dataFrame,schema.getColumnNames())); }
Example 5
Source File: RecordConverterTest.java From DataVec with Apache License 2.0 | 5 votes |
@Test public void toRecords_PassInClassificationDataSet_ExpectNDArrayAndIntWritables() { INDArray feature1 = Nd4j.create(new double[]{4, -5.7, 10, -0.1}); INDArray feature2 = Nd4j.create(new double[]{11, .7, -1.3, 4}); INDArray label1 = Nd4j.create(new double[]{0, 0, 1, 0}); INDArray label2 = Nd4j.create(new double[]{0, 1, 0, 0}); DataSet dataSet = new DataSet(Nd4j.vstack(Lists.newArrayList(feature1, feature2)), Nd4j.vstack(Lists.newArrayList(label1, label2))); List<List<Writable>> writableList = RecordConverter.toRecords(dataSet); assertEquals(2, writableList.size()); testClassificationWritables(feature1, 2, writableList.get(0)); testClassificationWritables(feature2, 1, writableList.get(1)); }
Example 6
Source File: RecordConverterTest.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void toRecords_PassInClassificationDataSet_ExpectNDArrayAndIntWritables() { INDArray feature1 = Nd4j.create(new double[]{4, -5.7, 10, -0.1}, new long[]{1, 4}, DataType.FLOAT); INDArray feature2 = Nd4j.create(new double[]{11, .7, -1.3, 4}, new long[]{1, 4}, DataType.FLOAT); INDArray label1 = Nd4j.create(new double[]{0, 0, 1, 0}, new long[]{1, 4}, DataType.FLOAT); INDArray label2 = Nd4j.create(new double[]{0, 1, 0, 0}, new long[]{1, 4}, DataType.FLOAT); DataSet dataSet = new DataSet(Nd4j.vstack(Lists.newArrayList(feature1, feature2)), Nd4j.vstack(Lists.newArrayList(label1, label2))); List<List<Writable>> writableList = RecordConverter.toRecords(dataSet); assertEquals(2, writableList.size()); testClassificationWritables(feature1, 2, writableList.get(0)); testClassificationWritables(feature2, 1, writableList.get(1)); }