Search in sources :

Example 1 with GroupByBatchOp

use of com.alibaba.alink.operator.batch.sql.GroupByBatchOp in project Alink by alibaba.

the class DeepARTrainBatchOpTest method testDeepARTrainBatchOp.

@Test
public void testDeepARTrainBatchOp() throws Exception {
    BatchOperator.setParallelism(1);
    List<Row> data = Arrays.asList(Row.of(0, Timestamp.valueOf("2021-11-01 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-02 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-03 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-04 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-05 00:00:00"), 100.0));
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(data, "id int, ts timestamp, series double");
    DeepARTrainBatchOp deepARTrainBatchOp = new DeepARTrainBatchOp().setTimeCol("ts").setSelectedCol("series").setNumEpochs(10).setWindow(2).setStride(1);
    GroupByBatchOp groupData = new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, series) as mtable_agg_series");
    DeepARPredictBatchOp deepARPredictBatchOp = new DeepARPredictBatchOp().setPredictNum(2).setPredictionCol("pred").setValueCol("mtable_agg_series");
    deepARPredictBatchOp.linkFrom(deepARTrainBatchOp.linkFrom(memSourceBatchOp), groupData.linkFrom(memSourceBatchOp)).print();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) GroupByBatchOp(com.alibaba.alink.operator.batch.sql.GroupByBatchOp) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 2 with GroupByBatchOp

use of com.alibaba.alink.operator.batch.sql.GroupByBatchOp in project Alink by alibaba.

the class ProphetBatchOpTest method testModel.

@Test
public void testModel() throws Exception {
    // AlinkGlobalConfiguration.setPrintProcessInfo(true);
    Row[] rowsData = new Row[] { Row.of("1", new Timestamp(117, 11, 1, 0, 0, 0, 0), 9.59076113897809), Row.of("1", new Timestamp(117, 11, 2, 0, 0, 0, 0), 8.51959031601596), Row.of("2", new Timestamp(117, 11, 3, 0, 0, 0, 0), 9.59076113897809), Row.of("1", new Timestamp(117, 11, 4, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 5, 0, 0, 0, 0), 8.51959031601596), Row.of("1", new Timestamp(117, 11, 6, 0, 0, 0, 0), 8.07246736935477), Row.of("2", new Timestamp(117, 11, 7, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 8, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 9, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 10, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 11, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 12, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 13, 0, 0, 0, 0), 8.18367658262066), Row.of("2", new Timestamp(117, 11, 14, 0, 0, 0, 0), 8.18367658262066), Row.of("1", new Timestamp(117, 11, 15, 0, 0, 0, 0), 7.8935720735049), Row.of("1", new Timestamp(117, 11, 16, 0, 0, 0, 0), 7.78364059622125), Row.of("2", new Timestamp(117, 11, 17, 0, 0, 0, 0), 8.07246736935477), Row.of("1", new Timestamp(117, 11, 18, 0, 0, 0, 0), 8.41405243249672), Row.of("1", new Timestamp(117, 11, 19, 0, 0, 0, 0), 8.82922635473185), Row.of("1", new Timestamp(117, 11, 20, 0, 0, 0, 0), 8.38251828808963), Row.of("1", new Timestamp(117, 11, 21, 0, 0, 0, 0), 8.06965530688617), Row.of("1", new Timestamp(117, 11, 22, 0, 0, 0, 0), 9.59076113897809), Row.of("1", new Timestamp(117, 11, 23, 0, 0, 0, 0), 8.51959031601596), Row.of("1", new Timestamp(117, 11, 24, 0, 0, 0, 0), 8.18367658262066), Row.of("1", new Timestamp(117, 11, 25, 0, 0, 0, 0), 8.07246736935477), Row.of("1", new Timestamp(117, 11, 26, 0, 0, 0, 0), 7.8935720735049), Row.of("1", new Timestamp(117, 11, 27, 0, 0, 0, 0), 7.78364059622125), Row.of("1", new Timestamp(117, 11, 28, 0, 0, 0, 0), 8.41405243249672), Row.of("1", new Timestamp(117, 11, 29, 0, 0, 0, 0), 8.82922635473185), Row.of("1", new Timestamp(117, 12, 1, 0, 0, 0, 0), 8.38251828808963), Row.of("1", new Timestamp(117, 12, 2, 0, 0, 0, 0), 8.06965530688617), Row.of("2", new Timestamp(117, 12, 3, 0, 0, 0, 0), 8.07246736935477), Row.of("2", new Timestamp(117, 12, 4, 0, 0, 0, 0), 7.8935720735049), Row.of("2", new Timestamp(117, 12, 5, 0, 0, 0, 0), 7.78364059622125), Row.of("2", new Timestamp(117, 12, 6, 0, 0, 0, 0), 8.41405243249672), Row.of("2", new Timestamp(117, 12, 7, 0, 0, 0, 0), 8.82922635473185), Row.of("2", new Timestamp(117, 12, 8, 0, 0, 0, 0), 8.38251828808963), Row.of("2", new Timestamp(117, 12, 9, 0, 0, 0, 0), 8.06965530688617) };
    String[] colNames = new String[] { "id", "ds1", "y1" };
    // train batch model.
    MemSourceBatchOp source = new MemSourceBatchOp(Arrays.asList(rowsData), colNames);
    ProphetTrainBatchOp model = new ProphetTrainBatchOp().setTimeCol("ds1").setValueCol("y1");
    source.link(model).print();
    // construct times series by id.
    GroupByBatchOp groupData = new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, val) as data");
    ProphetPredictBatchOp prophetPredict = new ProphetPredictBatchOp().setValueCol("ts").setPredictNum(4).setPredictionCol("pred");
    prophetPredict.linkFrom(model, source.link(groupData)).print();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) GroupByBatchOp(com.alibaba.alink.operator.batch.sql.GroupByBatchOp) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 3 with GroupByBatchOp

use of com.alibaba.alink.operator.batch.sql.GroupByBatchOp in project Alink by alibaba.

the class HoltWintersBatchOpTest method test.

@Test
public void test() throws Exception {
    List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
    MemSourceBatchOp source = new MemSourceBatchOp(mTableData, new String[] { "id", "ts", "val" });
    source.link(new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, val) as data")).link(new HoltWintersBatchOp().setValueCol("data").setPredictionCol("pred").setPredictNum(12)).print();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) GroupByBatchOp(com.alibaba.alink.operator.batch.sql.GroupByBatchOp) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 4 with GroupByBatchOp

use of com.alibaba.alink.operator.batch.sql.GroupByBatchOp in project Alink by alibaba.

the class ShiftBatchOpTest method test.

@Test
public void test() throws Exception {
    List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
    MemSourceBatchOp source = new MemSourceBatchOp(mTableData, new String[] { "id", "ts", "val" });
    source.link(new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, val) as data")).link(new ShiftBatchOp().setValueCol("data").setShiftNum(7).setPredictNum(12).setPredictionCol("predict")).print();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) GroupByBatchOp(com.alibaba.alink.operator.batch.sql.GroupByBatchOp) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 5 with GroupByBatchOp

use of com.alibaba.alink.operator.batch.sql.GroupByBatchOp in project Alink by alibaba.

the class ArimaBatchOpTest method test.

@Test
public void test() throws Exception {
    List<Row> mTableData = Arrays.asList(Row.of(1, new Timestamp(1), 10.0), Row.of(1, new Timestamp(2), 11.0), Row.of(1, new Timestamp(3), 12.0), Row.of(1, new Timestamp(4), 13.0), Row.of(1, new Timestamp(5), 14.0), Row.of(1, new Timestamp(6), 15.0), Row.of(1, new Timestamp(7), 16.0), Row.of(1, new Timestamp(8), 17.0), Row.of(1, new Timestamp(9), 18.0), Row.of(1, new Timestamp(10), 19.0));
    MemSourceBatchOp source = new MemSourceBatchOp(mTableData, new String[] { "id", "ts", "val" });
    source.link(new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, val) as data")).link(new ArimaBatchOp().setValueCol("data").setOrder(new int[] { 1, 2, 1 }).setPredictNum(12).setPredictionCol("predict")).print();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) GroupByBatchOp(com.alibaba.alink.operator.batch.sql.GroupByBatchOp) Row(org.apache.flink.types.Row) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

GroupByBatchOp (com.alibaba.alink.operator.batch.sql.GroupByBatchOp)13 Test (org.junit.Test)13 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)11 Row (org.apache.flink.types.Row)11 Timestamp (java.sql.Timestamp)7 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)2 AppendIdBatchOp (com.alibaba.alink.operator.batch.dataproc.AppendIdBatchOp)2 RandomTableSourceBatchOp (com.alibaba.alink.operator.batch.source.RandomTableSourceBatchOp)2 SelectBatchOp (com.alibaba.alink.operator.batch.sql.SelectBatchOp)2 AppendIdStreamOp (com.alibaba.alink.operator.stream.dataproc.AppendIdStreamOp)2 HopTimeWindowStreamOp (com.alibaba.alink.operator.stream.feature.HopTimeWindowStreamOp)2 TumbleTimeWindowStreamOp (com.alibaba.alink.operator.stream.feature.TumbleTimeWindowStreamOp)2 AkSinkStreamOp (com.alibaba.alink.operator.stream.sink.AkSinkStreamOp)2 RandomTableSourceStreamOp (com.alibaba.alink.operator.stream.source.RandomTableSourceStreamOp)2 SelectStreamOp (com.alibaba.alink.operator.stream.sql.SelectStreamOp)2 DeepARPredictStreamOp (com.alibaba.alink.operator.stream.timeseries.DeepARPredictStreamOp)2 Path (org.apache.flink.core.fs.Path)2 FlattenMTableBatchOp (com.alibaba.alink.operator.batch.dataproc.FlattenMTableBatchOp)1 ColumnsToVectorBatchOp (com.alibaba.alink.operator.batch.dataproc.format.ColumnsToVectorBatchOp)1 ColumnsToVectorStreamOp (com.alibaba.alink.operator.stream.dataproc.format.ColumnsToVectorStreamOp)1