Java 类名:com.alibaba.alink.operator.batch.dataproc.MaxAbsScalerPredictBatchOp
Python 类名:MaxAbsScalerPredictBatchOp

功能介绍

  • 绝对值最大标准化是对数据按照最大值和最小值进行标准化的组件, 将数据归一到-1和1之间。
  • 需要读入MaxAbsScalerTrainBatchOp生成的模型

    参数说明

    | 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- | | modelFilePath | 模型的文件路径 | 模型的文件路径 | String | | | null | | outputCols | 输出结果列列名数组 | 输出结果列列名数组,可选,默认null | String[] | | | null | | numThreads | 组件多线程线程个数 | 组件多线程线程个数 | Integer | | | 1 |

代码示例

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. colnames = ["col1", "col2", "col3"]
  14. selectedColNames = ["col2", "col3"]
  15. inOp = BatchOperator.fromDataframe(df, schemaStr='col1 string, col2 double, col3 long')
  16. # train
  17. trainOp = MaxAbsScalerTrainBatchOp()\
  18. .setSelectedCols(selectedColNames)
  19. trainOp.linkFrom(inOp)
  20. # batch predict
  21. predictOp = MaxAbsScalerPredictBatchOp()
  22. predictOp.linkFrom(trainOp, inOp).print()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.dataproc.MaxAbsScalerPredictBatchOp;
  4. import com.alibaba.alink.operator.batch.dataproc.MaxAbsScalerTrainBatchOp;
  5. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  6. import org.junit.Test;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. public class MaxAbsScalerPredictBatchOpTest {
  10. @Test
  11. public void testMaxAbsScalerPredictBatchOp() throws Exception {
  12. List <Row> df = Arrays.asList(
  13. Row.of("a", 10.0, 100),
  14. Row.of("b", -2.5, 9),
  15. Row.of("c", 100.2, 1),
  16. Row.of("d", -99.9, 100),
  17. Row.of("a", 1.4, 1),
  18. Row.of("b", -2.2, 9),
  19. Row.of("c", 100.9, 1)
  20. );
  21. String[] selectedColNames = new String[] {"col2", "col3"};
  22. BatchOperator <?> inOp = new MemSourceBatchOp(df, "col1 string, col2 double, col3 int");
  23. BatchOperator <?> trainOp = new MaxAbsScalerTrainBatchOp()
  24. .setSelectedCols(selectedColNames);
  25. trainOp.linkFrom(inOp);
  26. BatchOperator <?> predictOp = new MaxAbsScalerPredictBatchOp();
  27. predictOp.linkFrom(trainOp, inOp).print();
  28. }
  29. }

运行结果

| col1 | col2 | col3 | | —- | —- | —- |

| a | 0.0991 | 1.0000 |

| b | -0.0248 | 0.0900 |

| c | 0.9931 | 0.0100 |

| d | -0.9901 | 1.0000 |

| a | 0.0139 | 0.0100 |

| b | -0.0218 | 0.0900 |

| c | 1.0000 | 0.0100 |