Java 类名:com.alibaba.alink.operator.batch.regression.IsotonicRegPredictBatchOp
Python 类名:IsotonicRegPredictBatchOp

功能介绍

保序回归在观念上是寻找一组非递减的片段连续线性函数(piecewise linear continuous functions),即保序函数,使其与样本尽可能的接近。

参数说明

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

| predictionCol | 预测结果列名 | 预测结果列名 | String | ✓ | | |

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

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

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. [0.35, 1],
  6. [0.6, 1],
  7. [0.55, 1],
  8. [0.5, 1],
  9. [0.18, 0],
  10. [0.1, 1],
  11. [0.8, 1],
  12. [0.45, 0],
  13. [0.4, 1],
  14. [0.7, 0],
  15. [0.02, 1],
  16. [0.3, 0],
  17. [0.27, 1],
  18. [0.2, 0],
  19. [0.9, 1]
  20. ])
  21. data = BatchOperator.fromDataframe(df, schemaStr="feature double, label double")
  22. trainOp = IsotonicRegTrainBatchOp()\
  23. .setFeatureCol("feature")\
  24. .setLabelCol("label")
  25. model = trainOp.linkFrom(data)
  26. predictOp = IsotonicRegPredictBatchOp()\
  27. .setPredictionCol("result")
  28. predictOp.linkFrom(model, data).print()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.regression.IsotonicRegPredictBatchOp;
  4. import com.alibaba.alink.operator.batch.regression.IsotonicRegTrainBatchOp;
  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 IsotonicRegPredictBatchOpTest {
  10. @Test
  11. public void testIsotonicRegPredictBatchOp() throws Exception {
  12. List <Row> df = Arrays.asList(
  13. Row.of(0.35, 1.0),
  14. Row.of(0.6, 1.0),
  15. Row.of(0.55, 1.0),
  16. Row.of(0.5, 1.0),
  17. Row.of(0.18, 0.0),
  18. Row.of(0.1, 1.0),
  19. Row.of(0.8, 1.0),
  20. Row.of(0.45, 0.0),
  21. Row.of(0.4, 1.0),
  22. Row.of(0.7, 0.0),
  23. Row.of(0.02, 1.0),
  24. Row.of(0.3, 0.0),
  25. Row.of(0.27, 1.0),
  26. Row.of(0.2, 0.0),
  27. Row.of(0.9, 1.0)
  28. );
  29. BatchOperator <?> data = new MemSourceBatchOp(df, "feature double, label double");
  30. BatchOperator <?> trainOp = new IsotonicRegTrainBatchOp()
  31. .setFeatureCol("feature")
  32. .setLabelCol("label");
  33. BatchOperator model = trainOp.linkFrom(data);
  34. BatchOperator <?> predictOp = new IsotonicRegPredictBatchOp()
  35. .setPredictionCol("result");
  36. predictOp.linkFrom(model, data).print();
  37. }
  38. }

运行结果

模型结果

| model_id | model_info | | —- | —- |

| 0 | {“vectorCol”:””col2””,”featureIndex”:”0”,”featureCol”:null} |

| 1048576 | [0.02,0.3,0.35,0.45,0.5,0.7] |

| 2097152 | [0.5,0.5,0.6666666865348816,0.6666666865348816,0.75,0.75] |

预测结果

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

| 1.0 | 0.9 | 1.0 | 0.75 |

| 0.0 | 0.7 | 1.0 | 0.75 |

| 1.0 | 0.35 | 1.0 | 0.6666666865348816 |

| 1.0 | 0.02 | 1.0 | 0.5 |

| 1.0 | 0.27 | 1.0 | 0.5 |

| 1.0 | 0.5 | 1.0 | 0.75 |

| 0.0 | 0.18 | 1.0 | 0.5 |

| 0.0 | 0.45 | 1.0 | 0.6666666865348816 |

| 1.0 | 0.8 | 1.0 | 0.75 |

| 1.0 | 0.6 | 1.0 | 0.75 |

| 1.0 | 0.4 | 1.0 | 0.6666666865348816 |

| 0.0 | 0.3 | 1.0 | 0.5 |

| 1.0 | 0.55 | 1.0 | 0.75 |

| 0.0 | 0.2 | 1.0 | 0.5 |

| 1.0 | 0.1 | 1.0 | 0.5 |