Java 类名:com.alibaba.alink.operator.stream.evaluation.EvalMultiClassStreamOp
Python 类名:EvalMultiClassStreamOp

功能介绍

多分类评估是对多分类算法的预测结果进行效果评估。
支持Roc曲线,LiftChart曲线,K-S曲线,Recall-Precision曲线绘制。
流式的实验支持累计统计和窗口统计,除却上述四条曲线外,还给出Auc/Kappa/Accuracy/Logloss随时间的变化曲线。
给出整体的评估指标包括:AUC、K-S、PRC, 不同阈值下的Precision、Recall、F-Measure、Sensitivity、Accuracy、Specificity和Kappa。

混淆矩阵

多分类评估 (EvalMultiClassStreamOp) - 图1#### Precision

Recall

F-Measure

Sensitivity

Accuracy

Specificity

Kappa

Logloss

参数说明

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

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

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

| predictionDetailCol | 预测详细信息列名 | 预测详细信息列名 | String | | | |

| timeInterval | 时间间隔 | 流式数据统计的时间间隔 | Double | | | 3.0 |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. ["prefix1", "{\"prefix1\": 0.9, \"prefix0\": 0.1}"],
  6. ["prefix1", "{\"prefix1\": 0.8, \"prefix0\": 0.2}"],
  7. ["prefix1", "{\"prefix1\": 0.7, \"prefix0\": 0.3}"],
  8. ["prefix0", "{\"prefix1\": 0.75, \"prefix0\": 0.25}"],
  9. ["prefix0", "{\"prefix1\": 0.6, \"prefix0\": 0.4}"]
  10. ])
  11. inOp = StreamOperator.fromDataframe(df, schemaStr='label string, detailInput string')
  12. EvalMultiClassStreamOp().setLabelCol("label").setPredictionDetailCol("detailInput").setTimeInterval(0.001).linkFrom(inOp).print()
  13. StreamOperator.execute()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.stream.StreamOperator;
  3. import com.alibaba.alink.operator.stream.evaluation.EvalMultiClassStreamOp;
  4. import com.alibaba.alink.operator.stream.source.MemSourceStreamOp;
  5. import org.junit.Test;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. public class EvalMultiClassStreamOpTest {
  9. @Test
  10. public void testEvalMultiClassStreamOp() throws Exception {
  11. List <Row> df = Arrays.asList(
  12. Row.of("prefix1", "{\"prefix1\": 0.9, \"prefix0\": 0.1}"),
  13. Row.of("prefix1", "{\"prefix1\": 0.8, \"prefix0\": 0.2}"),
  14. Row.of("prefix1", "{\"prefix1\": 0.7, \"prefix0\": 0.3}"),
  15. Row.of("prefix0", "{\"prefix1\": 0.75, \"prefix0\": 0.25}"),
  16. Row.of("prefix0", "{\"prefix1\": 0.6, \"prefix0\": 0.4}")
  17. );
  18. StreamOperator <?> inOp = new MemSourceStreamOp(df, "label string, detailInput string");
  19. new EvalMultiClassStreamOp().setLabelCol("label").setPredictionDetailCol("detailInput").setTimeInterval(0.001)
  20. .linkFrom(inOp).print();
  21. StreamOperator.execute();
  22. }
  23. }

运行结果

| Statistics | Data | | —- | —- |

| all | {“SensitivityArray”:”[1.0,0.0,1.0,0.5,1.0]”,”ConfusionMatrix”:”[[1,0],[0,0]]”,”MacroRecall”:”0.5”,”MacroSpecificity”:”0.5”,”FalsePositiveRateArray”:”[0.0,0.0,0.0,0.0,0.0]”,”TruePositiveRateArray”:”[1.0,0.0,1.0,0.5,1.0]”,”MacroAccuracy”:”1.0”,”RecallArray”:”[1.0,0.0,1.0,0.5,1.0]”,”KappaArray”:”[1.0,1.0,1.0,1.0,1.0]”,”MicroFalseNegativeRate”:”0.0”,”WeightedRecall”:”1.0”,”WeightedPrecision”:”1.0”,”MacroPrecision”:”1.0”,”ActualLabelFrequency”:”[1,0]”,”PrecisionArray”:”[1.0,1.0,1.0,1.0,1.0]”,”MicroTruePositiveRate”:”1.0”,”MacroKappa”:”1.0”,”MicroSpecificity”:”1.0”,”PredictLabelProportion”:”[1.0,0.0]”,”F1Array”:”[1.0,0.0,1.0,0.5,1.0]”,”MacroFalsePositiveRate”:”0.0”,”FalseNegativeRateArray”:”[0.0,0.0,0.0,0.0,0.0]”,”TrueNegativeRateArray”:”[0.0,1.0,0.0,0.5,1.0]”,”MacroF1”:”0.5”,”LabelArray”:”[“prefix1”,”prefix0”]”,”WeightedTruePositiveRate”:”1.0”,”WeightedKappa”:”1.0”,”TotalSamples”:”1”,”MicroTrueNegativeRate”:”1.0”,”MacroTruePositiveRate”:”0.5”,”MicroSensitivity”:”1.0”,”WeightedAccuracy”:”1.0”,”AccuracyArray”:”[1.0,1.0,1.0,1.0,1.0]”,”Accuracy”:”1.0”,”WeightedFalseNegativeRate”:”0.0”,”MicroF1”:”1.0”,”WeightedSpecificity”:”0.0”,”WeightedF1”:”1.0”,”MicroAccuracy”:”1.0”,”WeightedTrueNegativeRate”:”0.0”,”Kappa”:”1.0”,”MacroSensitivity”:”0.5”,”SpecificityArray”:”[0.0,1.0,0.0,0.5,1.0]”,”ActualLabelProportion”:”[1.0,0.0]”,”PredictLabelFrequency”:”[1,0]”,”WeightedSensitivity”:”1.0”,”MicroRecall”:”1.0”,”MacroFalseNegativeRate”:”0.0”,”LogLoss”:”0.35667494393873245”,”MicroFalsePositiveRate”:”0.0”,”WeightedFalsePositiveRate”:”0.0”,”MacroTrueNegativeRate”:”0.5”,”MicroPrecision”:”1.0”,”MicroKappa”:”1.0”} |

| window | {“SensitivityArray”:”[1.0,0.0,1.0,0.5,1.0]”,”ConfusionMatrix”:”[[1,0],[0,0]]”,”MacroRecall”:”0.5”,”MacroSpecificity”:”0.5”,”FalsePositiveRateArray”:”[0.0,0.0,0.0,0.0,0.0]”,”TruePositiveRateArray”:”[1.0,0.0,1.0,0.5,1.0]”,”MacroAccuracy”:”1.0”,”RecallArray”:”[1.0,0.0,1.0,0.5,1.0]”,”KappaArray”:”[1.0,1.0,1.0,1.0,1.0]”,”MicroFalseNegativeRate”:”0.0”,”WeightedRecall”:”1.0”,”WeightedPrecision”:”1.0”,”MacroPrecision”:”1.0”,”ActualLabelFrequency”:”[1,0]”,”PrecisionArray”:”[1.0,1.0,1.0,1.0,1.0]”,”MicroTruePositiveRate”:”1.0”,”MacroKappa”:”1.0”,”MicroSpecificity”:”1.0”,”PredictLabelProportion”:”[1.0,0.0]”,”F1Array”:”[1.0,0.0,1.0,0.5,1.0]”,”MacroFalsePositiveRate”:”0.0”,”FalseNegativeRateArray”:”[0.0,0.0,0.0,0.0,0.0]”,”TrueNegativeRateArray”:”[0.0,1.0,0.0,0.5,1.0]”,”MacroF1”:”0.5”,”LabelArray”:”[“prefix1”,”prefix0”]”,”WeightedTruePositiveRate”:”1.0”,”WeightedKappa”:”1.0”,”TotalSamples”:”1”,”MicroTrueNegativeRate”:”1.0”,”MacroTruePositiveRate”:”0.5”,”MicroSensitivity”:”1.0”,”WeightedAccuracy”:”1.0”,”AccuracyArray”:”[1.0,1.0,1.0,1.0,1.0]”,”Accuracy”:”1.0”,”WeightedFalseNegativeRate”:”0.0”,”MicroF1”:”1.0”,”WeightedSpecificity”:”0.0”,”WeightedF1”:”1.0”,”MicroAccuracy”:”1.0”,”WeightedTrueNegativeRate”:”0.0”,”Kappa”:”1.0”,”MacroSensitivity”:”0.5”,”SpecificityArray”:”[0.0,1.0,0.0,0.5,1.0]”,”ActualLabelProportion”:”[1.0,0.0]”,”PredictLabelFrequency”:”[1,0]”,”WeightedSensitivity”:”1.0”,”MicroRecall”:”1.0”,”MacroFalseNegativeRate”:”0.0”,”LogLoss”:”0.35667494393873245”,”MicroFalsePositiveRate”:”0.0”,”WeightedFalsePositiveRate”:”0.0”,”MacroTrueNegativeRate”:”0.5”,”MicroPrecision”:”1.0”,”MicroKappa”:”1.0”} |