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

功能介绍

vector绝对值最大标准化是对vector数据按照最大值和最小值进行标准化的组件, 将数据归一到-1和1之间。
预测组件使用VectorMaxAbsScalerTrainBatchOp训练生成的模型,处理数据之后生成结果数据。

参数说明

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

| 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. ["a", "10.0, 100"],
  6. ["b", "-2.5, 9"],
  7. ["c", "100.2, 1"],
  8. ["d", "-99.9, 100"],
  9. ["a", "1.4, 1"],
  10. ["b", "-2.2, 9"],
  11. ["c", "100.9, 1"]
  12. ])
  13. data = BatchOperator.fromDataframe(df, schemaStr="col string, vec string")
  14. dataStream = StreamOperator.fromDataframe(df, schemaStr="col string, vec string")
  15. trainOp = VectorMaxAbsScalerTrainBatchOp()\
  16. .setSelectedCol("vec")
  17. model = trainOp.linkFrom(data)
  18. streamPredictOp = VectorMaxAbsScalerPredictStreamOp(model)
  19. streamPredictOp.linkFrom(dataStream).print()
  20. 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.VectorMaxAbsScalerTrainBatchOp;
  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.VectorMaxAbsScalerPredictStreamOp;
  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 VectorMaxAbsScalerPredictStreamOpTest {
  12. @Test
  13. public void testVectorMaxAbsScalerPredictStreamOp() throws Exception {
  14. List <Row> df = Arrays.asList(
  15. Row.of("a", "10.0, 100"),
  16. Row.of("b", "-2.5, 9"),
  17. Row.of("c", "100.2, 1"),
  18. Row.of("d", "-99.9, 100"),
  19. Row.of("a", "1.4, 1"),
  20. Row.of("b", "-2.2, 9"),
  21. Row.of("c", "100.9, 1")
  22. );
  23. BatchOperator <?> data = new MemSourceBatchOp(df, "col string, vec string");
  24. StreamOperator <?> dataStream = new MemSourceStreamOp(df, "col string, vec string");
  25. BatchOperator <?> trainOp = new VectorMaxAbsScalerTrainBatchOp()
  26. .setSelectedCol("vec");
  27. BatchOperator <?> model = trainOp.linkFrom(data);
  28. StreamOperator <?> streamPredictOp = new VectorMaxAbsScalerPredictStreamOp(model);
  29. streamPredictOp.linkFrom(dataStream).print();
  30. StreamOperator.execute();
  31. }
  32. }

运行结果

| col1 | vec | | —- | —- |

| c | 1.0,0.01 |

| b | -0.024777006937561942,0.09 |

| d | -0.9900891972249752,1.0 |

| a | 0.09910802775024777,1.0 |

| b | -0.02180376610505451,0.09 |

| c | 0.9930624380574826,0.01 |

| a | 0.013875123885034686,0.01 |