use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.
the class VectorMinMaxTest method test.
@Test
public void test() throws Exception {
BatchOperator batchData = new TableSourceBatchOp(GenerateData.getDenseBatch());
StreamOperator streamData = new TableSourceStreamOp(GenerateData.getDenseStream());
VectorMinMaxScalerTrainBatchOp op = new VectorMinMaxScalerTrainBatchOp().setSelectedCol("vec").linkFrom(batchData);
List<Row> rows = new VectorMinMaxScalerPredictBatchOp().linkFrom(op, batchData).collect();
assertEquals(rows.get(0).getField(0), new DenseVector(new double[] { 0.4, 1.0 }));
assertEquals(rows.get(1), Row.of(new DenseVector(new double[] { 0., 0.0 })));
assertEquals(rows.get(2), Row.of(new DenseVector(new double[] { 1.0, 1.0 })));
new VectorMinMaxScalerPredictStreamOp(op).linkFrom(streamData).print();
StreamOperator.execute();
}
use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.
the class VectorMinMaxTest method testModelInfo.
@Test
public void testModelInfo() {
BatchOperator batchData = new TableSourceBatchOp(GenerateData.getDenseBatch());
VectorMinMaxScalerTrainBatchOp trainOp = new VectorMinMaxScalerTrainBatchOp().setSelectedCol("vec").linkFrom(batchData);
VectorMinMaxScalerModelInfo modelInfo = trainOp.getModelInfoBatchOp().collectModelInfo();
System.out.println(modelInfo.getMaxs().length);
System.out.println(modelInfo.getMins().length);
System.out.println(modelInfo.toString());
}
use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.
the class SampleBatchOpTest method test.
@Test
public void test() throws Exception {
TableSourceBatchOp tableSourceBatchOp = new TableSourceBatchOp(getBatchTable());
long cnt = tableSourceBatchOp.link(new SampleBatchOp(0.5, false)).count();
assert cnt >= 0 && cnt <= 10;
}
use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.
the class SqliteCatalogTest method sinkBatch.
@Test
public void sinkBatch() throws Exception {
Row[] rows = new Row[] { Row.of(new byte[] { 0, 1 }, new BigDecimal("0.00"), (byte) 0, (short) 0, 0, 0.0f, 0.0, 0, new Date(0), new Time(0), new Timestamp(0), "string", "string", new byte[] { 0, 1 }, "s", new byte[] { 0, 1 }, false, 0L) };
MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(Arrays.asList(rows), new TableSchema(new String[] { "col_bit", "col_decimal", "col_tinyint", "col_smallint", "col_int", "col_float", "col_double", "col_mediumint", "col_date", "col_time", "col_timestamp", "col_text", "col_varchar", "col_varbinary", "col_char", "col_binary", "col_boolean", "col_long" }, new TypeInformation<?>[] { Types.PRIMITIVE_ARRAY(Types.BYTE), Types.BIG_DEC, Types.BYTE, Types.SHORT, Types.INT, Types.FLOAT, Types.DOUBLE, Types.INT, Types.SQL_DATE, Types.SQL_TIME, Types.SQL_TIMESTAMP, Types.STRING, Types.STRING, Types.PRIMITIVE_ARRAY(Types.BYTE), Types.STRING, Types.PRIMITIVE_ARRAY(Types.BYTE), Types.BOOLEAN, Types.LONG }));
sqlite.sinkBatch(new ObjectPath(SQLITE_DB, SQLITE_DB_TABLE_1), memSourceBatchOp.getOutputTable(), new Params().set(HasOverwriteSink.OVERWRITE_SINK, true), memSourceBatchOp.getMLEnvironmentId());
BatchOperator.execute();
Assert.assertFalse(new TableSourceBatchOp(sqlite.sourceBatch(new ObjectPath(SQLITE_DB, SQLITE_DB_TABLE_1), new Params(), MLEnvironmentFactory.DEFAULT_ML_ENVIRONMENT_ID)).collect().isEmpty());
}
use of com.alibaba.alink.operator.batch.source.TableSourceBatchOp in project Alink by alibaba.
the class IsotonicRegressionTest method testIsotonicReg.
@Test
public void testIsotonicReg() throws Exception {
Table data = MLEnvironmentFactory.getDefault().createBatchTable(rows, new String[] { "id", "feature", "label" });
Table dataStream = MLEnvironmentFactory.getDefault().createStreamTable(rows, new String[] { "id", "feature", "label" });
IsotonicRegression op = new IsotonicRegression().setFeatureCol("feature").setLabelCol("label").setPredictionCol("result");
PipelineModel model = new Pipeline().add(op).fit(data);
BatchOperator<?> res = model.transform(new TableSourceBatchOp(data));
List<Row> list = res.select(new String[] { "id", "result" }).collect();
double[] actual = new double[] { 0.66, 0.75, 0.75, 0.75, 0.5, 0.5, 0.75, 0.66, 0.66, 0.75, 0.5, 0.5, 0.5, 0.5, 0.75 };
for (int i = 0; i < actual.length; i++) {
Assert.assertEquals((Double) list.get(i).getField(1), actual[(int) list.get(i).getField(0)], 0.01);
}
// StreamOperator<?> resStream = model.transform(new TableSourceStreamOp(dataStream));
// resStream.print();
// MLEnvironmentFactory.getDefault().getStreamExecutionEnvironment().execute();
}
Aggregations