Search in sources :

Example 11 with GroupByBatchOp

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

the class LSTNetTrainBatchOpTest method testLSTNetTrainBatchOp.

@Test
public void testLSTNetTrainBatchOp() 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"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-03 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-04 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-06 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-07 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-08 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-09 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-10 00:00:00"), 900.0), Row.of(0, Timestamp.valueOf("2021-11-11 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-12 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-13 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-14 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-15 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-16 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-17 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-18 00:00:00"), 100.0), Row.of(0, Timestamp.valueOf("2021-11-19 00:00:00"), 200.0), Row.of(0, Timestamp.valueOf("2021-11-20 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-11-21 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-11-22 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-11-23 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-24 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-25 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-26 00:00:00"), 900.0), Row.of(0, Timestamp.valueOf("2021-11-27 00:00:00"), 800.0), Row.of(0, Timestamp.valueOf("2021-11-28 00:00:00"), 700.0), Row.of(0, Timestamp.valueOf("2021-11-29 00:00:00"), 600.0), Row.of(0, Timestamp.valueOf("2021-11-30 00:00:00"), 500.0), Row.of(0, Timestamp.valueOf("2021-12-01 00:00:00"), 400.0), Row.of(0, Timestamp.valueOf("2021-12-02 00:00:00"), 300.0), Row.of(0, Timestamp.valueOf("2021-12-03 00:00:00"), 200.0));
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(data, "id int, ts timestamp, series double");
    LSTNetTrainBatchOp lstNetTrainBatchOp = new LSTNetTrainBatchOp().setTimeCol("ts").setSelectedCol("series").setNumEpochs(10).setWindow(24).setHorizon(1);
    GroupByBatchOp groupData = new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, series) as mtable_agg_series");
    LSTNetPredictBatchOp lstNetPredictBatchOp = new LSTNetPredictBatchOp().setPredictNum(1).setPredictionCol("pred").setReservedCols().setValueCol("mtable_agg_series");
    lstNetPredictBatchOp.linkFrom(lstNetTrainBatchOp.linkFrom(memSourceBatchOp), groupData.linkFrom(memSourceBatchOp.filter("ts >= TO_TIMESTAMP('2021-11-10 00:00:00')"))).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 12 with GroupByBatchOp

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

the class ProphetBatchOpTest method test2.

@Ignore
@Test
public void test2() throws Exception {
    AlinkGlobalConfiguration.setPrintProcessInfo(true);
    Row[] rowsData = new Row[] { Row.of("20210501", 0.1, "a1"), Row.of("20210502", 0.2, "a1"), Row.of("20210503", 0.3, "a1"), Row.of("20210504", 0.4, "a1"), Row.of("20210505", 0.5, "a1"), Row.of("20210506", 0.6, "a1"), Row.of("20210507", 0.7, "a1"), Row.of("20210508", 0.8, "a1"), Row.of("20210509", 0.9, "a1") };
    String[] colNames = new String[] { "ds", "f1", "f2" };
    // train batch model.
    MemSourceBatchOp source = new MemSourceBatchOp(Arrays.asList(rowsData), colNames);
    source.select("to_timestamp(ds, 'yyyyMMdd') as ds, f1 as val, f2 as id").link(new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("id, mtable_agg(ds, val) as data")).link(new ProphetBatchOp().setValueCol("data").setPredictionCol("pred").setPredictNum(12).setUncertaintySamples(0).setReservedCols("id").setPythonEnv("file:///Users/ning.cain/soft/miniforge3/envs/py39t/")).link(new FlattenMTableBatchOp().setReservedCols("id").setSelectedCol("pred").setSchemaStr("ds string, val double")).print();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) FlattenMTableBatchOp(com.alibaba.alink.operator.batch.dataproc.FlattenMTableBatchOp) GroupByBatchOp(com.alibaba.alink.operator.batch.sql.GroupByBatchOp) Row(org.apache.flink.types.Row) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with GroupByBatchOp

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

the class ProphetBatchOpTest method test.

@Test
public void test() throws Exception {
    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", "ts", "val" };
    // train batch model.
    MemSourceBatchOp source = new MemSourceBatchOp(Arrays.asList(rowsData), colNames);
    // construct times series by id.
    GroupByBatchOp groupData = new GroupByBatchOp().setGroupByPredicate("id").setSelectClause("mtable_agg(ts, val) as data");
    ProphetBatchOp prophetPredict = new ProphetBatchOp().setValueCol("data").setPredictNum(4).setPredictionCol("pred");
    prophetPredict.linkFrom(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)

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