Search in sources :

Example 1 with ProphetTrainBatchOp

use of com.alibaba.alink.operator.batch.timeseries.ProphetTrainBatchOp in project Alink by alibaba.

the class ProphetPredictStreamOpTest method testModel.

@Test
public void testModel() 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) };
    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");
    // .setPythonCmdPath("/Library/Frameworks/Python.framework/Versions/3.7/bin/python3");
    source.link(model);
    MemSourceStreamOp streamSource = new MemSourceStreamOp(Arrays.asList(rowsData), colNames);
    OverCountWindowStreamOp over = new OverCountWindowStreamOp().setTimeCol("ds1").setPrecedingRows(4).setClause("mtable_agg_preceding(ds1,y1) as tensor");
    ProphetPredictStreamOp streamPred = new ProphetPredictStreamOp(model).setValueCol("tensor").setPredictNum(1).setPredictionCol("pred").setPredictionDetailCol("pred_detail");
    LookupVectorInTimeSeriesStreamOp valueOp = new LookupVectorInTimeSeriesStreamOp().setTimeSeriesCol("pred").setTimeCol("ds1").setReservedCols("ds1", "tensor", "pred").setOutputCol("y_hat");
    streamSource.link(over).link(streamPred).link(valueOp).print();
    StreamOperator.execute();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) OverCountWindowStreamOp(com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp) Row(org.apache.flink.types.Row) ProphetTrainBatchOp(com.alibaba.alink.operator.batch.timeseries.ProphetTrainBatchOp) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Aggregations

MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)1 ProphetTrainBatchOp (com.alibaba.alink.operator.batch.timeseries.ProphetTrainBatchOp)1 OverCountWindowStreamOp (com.alibaba.alink.operator.stream.feature.OverCountWindowStreamOp)1 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)1 Timestamp (java.sql.Timestamp)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1