Java 类名:com.alibaba.alink.operator.batch.evaluation.EvalMultiLabelBatchOp
Python 类名:EvalMultiLabelBatchOp

功能介绍

多label分类评估是对多label分类算法的预测结果进行效果评估,支持下列评估指标。

subsetAccuracy

多标签分类评估 (EvalMultiLabelBatchOp) - 图1#### hammingLoss 多标签分类评估 (EvalMultiLabelBatchOp) - 图2#### accuracy 多标签分类评估 (EvalMultiLabelBatchOp) - 图3#### microPrecision 多标签分类评估 (EvalMultiLabelBatchOp) - 图4#### microRecall 多标签分类评估 (EvalMultiLabelBatchOp) - 图5#### microF1 多标签分类评估 (EvalMultiLabelBatchOp) - 图6#### precision 多标签分类评估 (EvalMultiLabelBatchOp) - 图7#### recall 多标签分类评估 (EvalMultiLabelBatchOp) - 图8#### f1

参数说明

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

| labelCol | 标签列名 | 输入表中的标签列名 | String | ✓ | | |

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

| labelRankingInfo | Object列列名 | Object列列名 | String | | | “object” |

| predictionRankingInfo | Object列列名 | Object列列名 | String | | | “object” |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. ["{\"object\":\"[0.0, 1.0]\"}", "{\"object\":\"[0.0, 2.0]\"}"],
  6. ["{\"object\":\"[0.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"],
  7. ["{\"object\":\"[]\"}", "{\"object\":\"[0.0]\"}"],
  8. ["{\"object\":\"[2.0]\"}", "{\"object\":\"[2.0]\"}"],
  9. ["{\"object\":\"[2.0, 0.0]\"}", "{\"object\":\"[2.0, 0.0]\"}"],
  10. ["{\"object\":\"[0.0, 1.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"],
  11. ["{\"object\":\"[1.0]\"}", "{\"object\":\"[1.0, 2.0]\"}"]
  12. ])
  13. source = BatchOperator.fromDataframe(df, "pred string, label string")
  14. evalMultiLabelBatchOp: EvalMultiLabelBatchOp = EvalMultiLabelBatchOp().setLabelCol("label").setPredictionCol("pred").linkFrom(source)
  15. metrics = evalMultiLabelBatchOp.collectMetrics()
  16. print(metrics)

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.evaluation.EvalMultiLabelBatchOp;
  4. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  5. import com.alibaba.alink.operator.common.evaluation.MultiLabelMetrics;
  6. import org.junit.Test;
  7. import java.util.Arrays;
  8. import java.util.List;
  9. public class EvalMultiLabelBatchOpTest {
  10. @Test
  11. public void testEvalMultiLabelBatchOp() throws Exception {
  12. List <Row> df = Arrays.asList(
  13. Row.of("{\"object\":\"[0.0, 1.0]\"}", "{\"object\":\"[0.0, 2.0]\"}"),
  14. Row.of("{\"object\":\"[0.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"),
  15. Row.of("{\"object\":\"[]\"}", "{\"object\":\"[0.0]\"}"),
  16. Row.of("{\"object\":\"[2.0]\"}", "{\"object\":\"[2.0]\"}"),
  17. Row.of("{\"object\":\"[2.0, 0.0]\"}", "{\"object\":\"[2.0, 0.0]\"}"),
  18. Row.of("{\"object\":\"[0.0, 1.0, 2.0]\"}", "{\"object\":\"[0.0, 1.0]\"}"),
  19. Row.of("{\"object\":\"[1.0]\"}", "{\"object\":\"[1.0, 2.0]\"}")
  20. );
  21. BatchOperator <?> source = new MemSourceBatchOp(df, "pred string, label string");
  22. EvalMultiLabelBatchOp evalMultiLabelBatchOp =
  23. new EvalMultiLabelBatchOp().setLabelCol("label").setPredictionCol(
  24. "pred").linkFrom(source);
  25. MultiLabelMetrics metrics = evalMultiLabelBatchOp.collectMetrics();
  26. System.out.println(metrics.toString());
  27. }
  28. }

运行结果

  1. -------------------------------- Metrics: --------------------------------
  2. microPrecision:0.7273
  3. microF1:0.6957
  4. subsetAccuracy:0.2857
  5. precision:0.6667
  6. recall:0.6429
  7. accuracy:0.5476
  8. f1:0.6381
  9. microRecall:0.6667
  10. hammingLoss:0.3333