全部產品
Search
文件中心

Platform For AI:離散值特徵分析

更新時間:Dec 28, 2024

離散值特徵分析是一種用於處理和分析離散特徵(即取值為有限個不同類別的特徵)的技術。該分析方法包括統計離散特徵的分布情況,計算每個離散值的Gini指數和熵(Entropy),以及評估特徵的重要性指標,如Gini增益(Gini Gain)、資訊增益(Information Gain)和資訊增益比(Information Gain Ratio),以便選擇對模型效能影響最大的特徵。

配置組件

方式一:可視化方式

在Designer工作流程頁面添加離散值特徵分析組件,並在介面右側配置相關參數:

參數

描述

特徵列

用來表現訓練樣本資料特徵的列。

標籤列

標籤欄位。

疏鬆陣列

當輸入表資料為稀疏格式時,需要設定KV格式的特徵。

方式二:PAI命令方式

使用PAI命令配置離散值特徵分析組件參數。您可以使用SQL指令碼組件進行PAI命令調用,詳情請參見情境4:在SQL指令碼組件中執行PAI命令

PAI
-name enum_feature_selection
-project algo_public
-DinputTableName=enumfeautreselection_input
-DlabelColName=label
-DfeatureColNames=col0,col1
-DenableSparse=false
-DoutputCntTableName=enumfeautreselection_output_cntTable
-DoutputValueTableName=enumfeautreselection_output_valuetable
-DoutputEnumValueTableName=enumfeautreselection_output_enumvaluetable;

參數名稱

是否必選

預設值

描述

inputTableName

輸入表的名稱。

inputTablePartitions

預設選擇全表

輸入表中,參與訓練的分區。系統支援以下格式:

  • Partition_name=value

  • name1=value1/name2=value2:多級分區

說明

指定多個分區時,分區之間使用英文逗號(,)分隔。

featureColNames

輸入表中,用於訓練的特徵列名。

labelColName

輸入表中,標籤列的名稱。

enableSparse

false

輸入資料是否為稀疏格式,取值範圍為{true,false}

kvFeatureColNames

預設選擇全表

KV格式的特徵。

kvDelimiter

英文冒號(:)

當輸入表資料為稀疏格式時,keyvalue之間的分隔字元。

itemDelimiter

英文逗號(,)

當輸入表資料為稀疏格式時,KV對之間的分隔字元。

outputCntTableName

不涉及

輸出離散特徵的枚舉值分布數表。

outputValueTableName

不涉及

輸出離散特徵的gini、entropy表。

outputEnumValueTableName

不涉及

輸出離散特徵枚舉值gini、entropy表。

lifecycle

表的生命週期。

coreNum

系統自動分配

計算的核心數,取值範圍為正整數。

memSizePerCore

系統自動分配

每個核心的記憶體,取值範圍為1 MB~65536 MB。

使用樣本

使用如下SQL語句,產生輸入資料:

drop table if exists enum_feature_selection_test_input;
create table enum_feature_selection_test_input
as
select
    *
from
(
    select
        '00' as col_string,
        1 as col_bigint,
        0.0 as col_double
    
    union all
        select
            cast(null as string) as col_string,
            0 as col_bigint,
            0.0 as col_double
        
    union all
        select
            '01' as col_string,
            0 as col_bigint,
            1.0 as col_double
        
    union all
        select
            '01' as col_string,
            1 as col_bigint,
            cast(null as double) as col_double
        
    union all
        select
            '01' as col_string,
            1 as col_bigint,
            1.0 as col_double
        
    union all
        select
            '00' as col_string,
            0 as col_bigint,
            0.0 as col_double
        
) tmp;

輸入資料如下所示:

+------------+------------+------------+
| col_string | col_bigint | col_double |
+------------+------------+------------+
| 01         | 1          | 1.0        |
| 01         | 0          | 1.0        |
| 01         | 1          | NULL       |
| NULL       | 0          | 0.0        |
| 00         | 1          | 0.0        |
| 00         | 0          | 0.0        |
+------------+------------+------------+

PAI命令方式

  • 運行命令

    drop table if exists enum_feature_selection_test_input_enum_value_output;
    drop table if exists enum_feature_selection_test_input_cnt_output;
    drop table if exists enum_feature_selection_test_input_value_output;
    PAI -name enum_feature_selection -project algo_public -DitemDelimiter=":" -Dlifecycle="28" -DoutputValueTableName="enum_feature_selection_test_input_value_output" -DkvDelimiter="," -DlabelColName="col_bigint" -DfeatureColNames="col_double,col_string" -DoutputEnumValueTableName="enum_feature_selection_test_input_enum_value_output" -DenableSparse="false" -DinputTableName="enum_feature_selection_test_input" -DoutputCntTableName="enum_feature_selection_test_input_cnt_output";
  • 運行結果

    • enum_feature_selection_test_input_cnt_output

      +------------+------------+------------+------------+
      | colname    | colvalue   | labelvalue | cnt        |
      +------------+------------+------------+------------+
      | col_double | NULL       | 1          | 1          |
      | col_double | 0          | 0          | 2          |
      | col_double | 0          | 1          | 1          |
      | col_double | 1          | 0          | 1          |
      | col_double | 1          | 1          | 1          |
      | col_string | NULL       | 0          | 1          |
      | col_string | 00         | 0          | 1          |
      | col_string | 00         | 1          | 1          |
      | col_string | 01         | 0          | 1          |
      | col_string | 01         | 1          | 2          |
      +------------+------------+------------+------------+
    • enum_feature_selection_test_input_value_output

      +------------+------------+------------+------------+------------+---------------+
      | colname    | gini       | entropy    | infogain   | ginigain   | infogainratio |
      +------------+------------+------------+------------+------------+---------------+
      | col_double | 0.3888888888888889 | 0.792481250360578 | 0.20751874963942196 | 0.1111111111111111 | 0.14221913160264427 |
      | col_string | 0.38888888888888884 | 0.792481250360578 | 0.20751874963942196 | 0.11111111111111116 | 0.14221913160264427 |
      +------------+------------+------------+------------+------------+---------------+
    • enum_feature_selection_test_input_enum_value_output

      +------------+------------+------------+------------+
      | colname    | colvalue   | gini       | entropy    |
      +------------+------------+------------+------------+
      | col_double | NULL       | 0.0        | 0.0        |
      | col_double | 0          | 0.22222222222222224 | 0.4591479170272448 |
      | col_double | 1          | 0.16666666666666666 | 0.3333333333333333 |
      | col_string | NULL       | 0.0        | 0.0        |
      | col_string | 00         | 0.16666666666666666 | 0.3333333333333333 |
      | col_string | 01         | 0.2222222222222222 | 0.4591479170272448 |
      +------------+------------+------------+------------+