Java 类名:com.alibaba.alink.operator.stream.dataproc.vector.VectorImputerPredictStreamOp
Python 类名:VectorImputerPredictStreamOp

功能介绍

  • 使用 Vecotor 缺失值填充模型对流Vector数据进行数据填充
  • 读取VectorImputerTrainBatchOp训练的模型

    参数说明

    | 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- |

| modelFilePath | 模型的文件路径 | 模型的文件路径 | String | | | null |

| outputCol | 输出结果列 | 输出结果列列名,可选,默认null | String | | | null |

| numThreads | 组件多线程线程个数 | 组件多线程线程个数 | Integer | | | 1 |

| modelStreamFilePath | 模型流的文件路径 | 模型流的文件路径 | String | | | null |

| modelStreamScanInterval | 扫描模型路径的时间间隔 | 描模型路径的时间间隔,单位秒 | Integer | | | 10 |

| modelStreamStartTime | 模型流的起始时间 | 模型流的起始时间。默认从当前时刻开始读。使用yyyy-mm-dd hh:mm:ss.fffffffff格式,详见Timestamp.valueOf(String s) | String | | | null |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. ["1:3 2:4 4:7", 1],
  6. ["0:3 5:5", 3],
  7. ["2:4 4:5", 4]
  8. ])
  9. dataStream = StreamOperator.fromDataframe(df, schemaStr="vec string, id bigint")
  10. data = BatchOperator.fromDataframe(df, schemaStr="vec string, id bigint")
  11. vecFill = VectorImputerTrainBatchOp().setSelectedCol("vec")
  12. model = data.link(vecFill)
  13. VectorImputerPredictStreamOp(model).setOutputCol("vec1").linkFrom(dataStream).print()
  14. StreamOperator.execute()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.dataproc.vector.VectorImputerTrainBatchOp;
  4. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  5. import com.alibaba.alink.operator.stream.StreamOperator;
  6. import com.alibaba.alink.operator.stream.dataproc.vector.VectorImputerPredictStreamOp;
  7. import com.alibaba.alink.operator.stream.source.MemSourceStreamOp;
  8. import org.junit.Test;
  9. import java.util.Arrays;
  10. import java.util.List;
  11. public class VectorImputerPredictStreamOpTest {
  12. @Test
  13. public void testVectorImputerPredictStreamOp() throws Exception {
  14. List <Row> df = Arrays.asList(
  15. Row.of("1:3 2:4 4:7", 1),
  16. Row.of("0:3 5:5", 3),
  17. Row.of("2:4 4:5", 4)
  18. );
  19. StreamOperator <?> dataStream = new MemSourceStreamOp(df, "vec string, id int");
  20. BatchOperator <?> data = new MemSourceBatchOp(df, "vec string, id int");
  21. BatchOperator <?> vecFill = new VectorImputerTrainBatchOp().setSelectedCol("vec");
  22. BatchOperator <?> model = data.link(vecFill);
  23. new VectorImputerPredictStreamOp(model).setOutputCol("vec1").linkFrom(dataStream).print();
  24. StreamOperator.execute();
  25. }
  26. }

运行结果

| vec | id | vec1 | | —- | —- | —- |

| 1:3,2:4,4:7 | 1 | 1:3.0 2:4.0 4:7.0 |

| 1:3,2:NaN | 3 | 1:3.0 2:4.0 |

| 2:4,4:5 | 4 | 2:4.0 4:5.0 |