功能介绍

标准化是对数据进行按正态化处理的组件

参数说明

名称 中文名称 描述 类型 是否必须? 默认值
selectedCols 选择的列名 计算列对应的列名列表 String[]
withMean 是否使用均值 是否使用均值,默认使用 Boolean true
withStd 是否使用标准差 是否使用标准差,默认使用 Boolean true

脚本示例

脚本

  1. data = np.array([
  2. ["a", 10.0, 100],
  3. ["b", -2.5, 9],
  4. ["c", 100.2, 1],
  5. ["d", -99.9, 100],
  6. ["a", 1.4, 1],
  7. ["b", -2.2, 9],
  8. ["c", 100.9, 1]
  9. ])
  10. colnames = ["col1", "col2", "col3"]
  11. selectedColNames = ["col2", "col3"]
  12. df = pd.DataFrame({"col1": data[:, 0], "col2": data[:, 1], "col3": data[:, 2]})
  13. inOp = dataframeToOperator(df, schemaStr='col1 string, col2 double, col3 long', op_type='batch')
  14. # train
  15. trainOp = StandardScalerTrainBatchOp()\
  16. .setSelectedCols(selectedColNames)
  17. trainOp.linkFrom(inOp)
  18. # batch predict
  19. predictOp = StandardScalerPredictBatchOp()
  20. predictOp.linkFrom(trainOp, inOp).print()
  21. # stream predict
  22. sinOp = dataframeToOperator(df, schemaStr='col1 string, col2 double, col3 long', op_type='stream')
  23. predictStreamOp = StandardScalerPredictStreamOp(trainOp)
  24. predictStreamOp.linkFrom(sinOp).print()
  25. StreamOperator.execute()

结果

  1. col1 col2 col3
  2. 0 a -0.078352 1.459581
  3. 1 b -0.259243 -0.481449
  4. 2 c 1.226961 -0.652089
  5. 3 d -1.668749 1.459581
  6. 4 a -0.202805 -0.652089
  7. 5 b -0.254902 -0.481449
  8. 6 c 1.237091 -0.652089