文档

多分类评估

更新时间:

多分类评估算法用于评估一个模型在处理多于两个类别的分类问题中的效能。该算法计算诸如准确率、召回率、F1分数以及混淆矩阵等指标,以量化模型对不同类别的分类精度。混淆矩阵展示了模型预测的类别与真实类别之间的关系,而其他指标则提供了每个类别分类正确与否的细节信息。这些度量帮助了解模型在各个类别上的表现,指导后续的模型优化。

配置组件

方法一:可视化方式

在Designer工作流页面添加多分类评估组件,并在界面右侧配置相关参数:

参数类型

参数

描述

字段设置

原分类结果列

可以选择原始标签列,分类数量不能大于1000。

预测分类结果列

预测分类列,一般情况下,该参数的字段名为prediction_result。

高级选项

如果选中高级选项复选框,则预测结果概率列参数生效。

预测结果概率列

用于计算模型的logloss,且仅对随机森林模型有效,其他模型设置后可能会报错;一般情况下,该参数的字段名为prediction_detail。

执行调优

核心数

核内存分配搭配使用,默认为系统自动分配。

核内存分配

每个核心的内存,单位:MB,默认为系统自动分配。

方法二:PAI命令方式

使用PAI命令配置多分类评估组件参数。您可以使用SQL脚本组件进行PAI命令调用,详情请参见场景4:在SQL脚本组件中执行PAI命令

PAI -name MultiClassEvaluation -project algo_public 
    -DinputTableName="test_input" 
    -DoutputTableName="test_output" 
    -DlabelColName="label" 
    -DpredictionColName="prediction_result" 
    -Dlifecycle=30;

参数

是否必选

默认值

参数描述

inputTableName

输入表的名称。

inputTablePartitions

全表

输入表的分区。

outputTableName

输出表的名称。

labelColName

输入表原始标签列名。

predictionColName

预测结果的标签列名。

predictionDetailColName

预测结果的概率列,例如{"A":0.2,"B":0.3,"C": 0.5}

lifecycle

输出表的生命周期。

coreNum

系统自动计算

核心数量。

memSizePerCore

系统自动计算

每个核心的内存。

使用示例

  1. 添加SQL脚本组件,输入以下SQL语句生成训练数据。

    drop table if exists multi_esti_test;
    create table multi_esti_test as
    select * from
    (
      select '0' as id,'A' as label,'A' as prediction,'{"A": 0.6, "B": 0.4}' as detail
      union all
      select '1' as id,'A' as label,'B' as prediction,'{"A": 0.45, "B": 0.55}' as detail
      union all
      select '2' as id,'A' as label,'A' as prediction,'{"A": 0.7, "B": 0.3}' as detail
      union all
      select '3' as id,'A' as label,'A' as prediction,'{"A": 0.9, "B": 0.1}' as detail
      union all
      select '4' as id,'B' as label,'B' as prediction,'{"A": 0.2, "B": 0.8}' as detail
      union all
      select '5' as id,'B' as label,'B' as prediction,'{"A": 0.1, "B": 0.9}' as detail
      union all
      select '6' as id,'B' as label,'A' as prediction,'{"A": 0.52, "B": 0.48}' as detail
      union all
      select '7' as id,'B' as label,'B' as prediction,'{"A": 0.4, "B": 0.6}' as detail
      union all
      select '8' as id,'B' as label,'A' as prediction,'{"A": 0.6, "B": 0.4}' as detail
      union all
      select '9' as id,'A' as label,'A' as prediction,'{"A": 0.75, "B": 0.25}' as detail
    )tmp;
  2. 添加SQL脚本组件,输入以下PAI命令进行训练。

    drop table if exists ${o1};
    PAI -name MultiClassEvaluation -project algo_public 
        -DinputTableName="multi_esti_test" 
        -DoutputTableName=${o1} 
        -DlabelColName="label" 
        -DpredictionColName="prediction" 
        -Dlifecycle=30;
  3. 右击上一步的组件,选择查看数据 > SQL脚本的输出,查看训练结果。

    | result                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
    | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | {
        "ActualLabelFrequencyList": [5,
            5],
        "ActualLabelProportionList": [0.5,
            0.5],
        "ConfusionMatrix": [[4,
                1],
            [2,
                3]],
        "LabelList": ["A",
            "B"],
        "LabelMeasureList": [{
                "Accuracy": 0.7,
                "F1": 0.7272727272727273,
                "FalseDiscoveryRate": 0.3333333333333333,
                "FalseNegative": 1,
                "FalseNegativeRate": 0.2,
                "FalsePositive": 2,
                "FalsePositiveRate": 0.4,
                "Kappa": 0.3999999999999999,
                "NegativePredictiveValue": 0.75,
                "Precision": 0.6666666666666666,
                "Sensitivity": 0.8,
                "Specificity": 0.6,
                "TrueNegative": 3,
                "TruePositive": 4},
            {
                "Accuracy": 0.7,
                "F1": 0.6666666666666666,
                "FalseDiscoveryRate": 0.25,
                "FalseNegative": 2,
                "FalseNegativeRate": 0.4,
                "FalsePositive": 1,
                "FalsePositiveRate": 0.2,
                "Kappa": 0.3999999999999999,
                "NegativePredictiveValue": 0.6666666666666666,
                "Precision": 0.75,
                "Sensitivity": 0.6,
                "Specificity": 0.8,
                "TrueNegative": 4,
                "TruePositive": 3}],
        "LabelNumber": 2,
        "OverallMeasures": {
            "Accuracy": 0.7,
            "Kappa": 0.3999999999999999,
            "LabelFrequencyBasedMicro": {
                "Accuracy": 0.7,
                "F1": 0.696969696969697,
                "FalseDiscoveryRate": 0.2916666666666666,
                "FalseNegative": 1.5,
                "FalseNegativeRate": 0.3,
                "FalsePositive": 1.5,
                "FalsePositiveRate": 0.3,
                "Kappa": 0.3999999999999999,
                "NegativePredictiveValue": 0.7083333333333333,
                "Precision": 0.7083333333333333,
                "Sensitivity": 0.7,
                "Specificity": 0.7,
                "TrueNegative": 3.5,
                "TruePositive": 3.5},
            "MacroAveraged": {
                "Accuracy": 0.7,
                "F1": 0.696969696969697,
                "FalseDiscoveryRate": 0.2916666666666666,
                "FalseNegative": 1.5,
                "FalseNegativeRate": 0.3,
                "FalsePositive": 1.5,
                "FalsePositiveRate": 0.3,
                "Kappa": 0.3999999999999999,
                "NegativePredictiveValue": 0.7083333333333333,
                "Precision": 0.7083333333333333,
                "Sensitivity": 0.7,
                "Specificity": 0.7,
                "TrueNegative": 3.5,
                "TruePositive": 3.5},
            "MicroAveraged": {
                "Accuracy": 0.7,
                "F1": 0.7,
                "FalseDiscoveryRate": 0.3,
                "FalseNegative": 3,
                "FalseNegativeRate": 0.3,
                "FalsePositive": 3,
                "FalsePositiveRate": 0.3,
                "Kappa": 0.3999999999999999,
                "NegativePredictiveValue": 0.7,
                "Precision": 0.7,
                "Sensitivity": 0.7,
                "Specificity": 0.7,
                "TrueNegative": 7,
                "TruePositive": 7}},
        "PredictedLabelFrequencyList": [6,
            4],
        "PredictedLabelProportionList": [0.6,
            0.4],
        "ProportionMatrix": [[0.8,
                0.2],
            [0.4,
                0.6]]} |

附录

如果您通过可视化方式运行多分类评估算法,可右击该组件,选择可视化分析,查看结果详情。image

image

image