本文為您介紹Designer提供的離散值特征分析。
離散值特征分析統計離散特征的分布情況。包括gini,entropy,gini gain,information gain,information gain ratio等指標。計算每個離散值對應的gini,entropy,計算單列對應的gini gain,information gain,information gain ratio。
gini index:
entropy:
組件配置
您可以使用以下任意一種方式,配置離散值特征分析組件參數。
方式一:可視化方式
在Designer工作流頁面配置組件參數。
參數 | 描述 |
特征列 | 用來表現訓練樣本數據特征的列。 |
標簽列 | 標簽字段。 |
稀疏矩陣 | 當輸入表數據為稀疏格式時,需要設置KV格式的特征。 |
方式二:PAI命令方式
使用PAI命令方式,配置該組件參數。您可以使用SQL腳本組件進行PAI命令調用,詳情請參見SQL腳本。
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 | 否 | 輸入表中,參與訓練的分區。系統支持以下格式:
說明 指定多個分區時,分區之間使用英文逗號(,)分隔。 | 默認選擇全表 |
featureColNames | 否 | 輸入表中,用于訓練的特征列名。 | 無 |
labelColName | 否 | 輸入表中,標簽列的名稱。 | 無 |
enableSparse | 否 | 輸入數據是否為稀疏格式,取值范圍為{true,false}。 | false |
kvFeatureColNames | 否 | KV格式的特征。 | 默認選擇全表 |
kvDelimiter | 否 | 當輸入表數據為稀疏格式時,key和value之間的分隔符。 | 英文冒號(:) |
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 | +------------+------------+------------+------------+