閱讀304 返回首頁    go 財經資訊


數據預處理__使用手冊(new)_機器學習-阿裏雲


目錄


加權采樣

以加權方式生成采樣數據;權重列必須為double或int類型,按照該列的value大小采樣;如col的值是1.2和1.0;則value=1.2所屬樣本的被采樣的概率就大一些。

參數設置

參數框

weighted_sample_param

  • 可手動輸入采樣個數(或者采樣比例)
  • 可以選擇放回采樣或者不放回采樣,默認為不放回,勾選後變為放回
  • 下拉框選擇加權列,加權列支持double型和bigint型
  • 可配置隨機數種子,默認係統自動分配

PAI 命令

  1. PAI -name WeightedSample -project algo_public -DprobCol="previous" -DsampleSize="500"
  2. -DoutputTableName="test2" -DinputPartitions="pt=20150501" -DinputTableName="bank_data_partition";

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表的表名 - -
inputTablePartitions 可選,輸入表中指定哪些分區參與訓練,格式為: partition_name=value。如果是多級,格式為name1=value1/name2=value2;如果指定多個分區,中間用’,’分開 - 輸入表的所有partition
outputTableName 必選,輸出結果表 - -
sampleSize 可選,采樣個數 正整數 默認為空
sampleRatio 可選,采樣比例 浮點數,範圍(0,1) 默認為空
probCol 必選,選擇的要加權的列,每個值代表所在record出現的權重,不需要歸一化 - -
replace 可選,是否放回,boolean類型 true / false false(默認不放回)
randomSeed 可選,隨機數種子 正整數 默認係統自動生成
lifecycle 可選,指定輸出表生命周期 正整數,[1,3650] 輸出表沒有生命周期
coreNum 可選,計算的核心數目 正整數 係統自動分配
memSizePerCore 可選,每個核心的內存(單位是兆) 正整數,(1, 65536) 係統自動分配

注:當sampleSize 與 sampleRatio都為空時,報錯; 當sampleSize 與 sampleRatio都不為空時,以sampleSize為準。


隨機采樣

以隨機方式生成采樣數據,每次采樣是各自獨立的。

參數設置

random_sample_param_settingrandom_sample_opt

  • 可手動輸入采樣個數(或者采樣比例)
  • 可以選擇放回采樣或者不放回采樣,默認為不放回,勾選後變為放回
  • 可配置隨機數種子,默認係統自動分配
  • 可以自己配置並發計算核心數目與內存,默認係統自動分配

PAI 命令

  1. pai -name RandomSample -project algo_public
  2. -DinputTableName=wbpc
  3. -DoutputTableName=wpbc_sample
  4. -DsampleSize=100
  5. -Dreplace=false
  6. -DrandomSeed=1007;

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表的表名 - -
inputTablePartitions 可選,輸入表中指定哪些分區參與訓練,格式為: partition_name=value。如果是多級,格式為name1=value1/name2=value2;如果指定多個分區,中間用’,’分開 - 輸入表的所有partition
outputTableName 必選,輸出結果表 - -
sampleSize 可選,采樣個數 - 默認為空
sampleRatio 可選,采樣比例,範圍(0,1) - 默認為空
replace 可選,是否放回,boolean類型 true / false false(默認不放回)
randomSeed 可選,隨機數種子 正整數 默認係統自動生成
lifecycle 可選,指定輸出表生命周期 正整數,[1,3650] 輸出表沒有生命周期
coreNum 可選,計算的核心數目 正整數 係統自動分配
memSizePerCore 可選,每個核心的內存(單位是兆) 正整數,(1, 65536) 係統自動分配

注:當sampleSize 與 sampleRatio都為空時,報錯; 當sampleSize 與 sampleRatio都不為空時,以sampleSize為準。


過濾與映射

對數據按照過濾表達式進行篩選;可以重命名字段名;

參數設置

1、通過where條件實現數據過濾,與SQL類似,如:screenshot

  1. - 篩選條件:目前操作符支持”=”,”!=”,”>”,”<”, “>=”和“<=”,like,rlike

2、重命名字段dd

PAI命令

  1. PAI -name Filter -project algo_public -DoutTableName="test_9" -DinputPartitions="pt=20150501"
  2. -DinputTableName="bank_data_partition" -Dfilter="age>=40";
  • name: 組件名字
  • project: project名字,用於指定算法所在空間。係統默認是algo_public,用戶自己更改後係統會報錯
  • outTableName: 輸出表的名字
  • inputPartitions:(可選)訓練輸入表分區。輸入表對應的輸入分區,選中全表則為None
  • inputTableName: 輸入表的名字
  • filter: where篩選條件,目前操作符支持”=”,”!=”,”>”,”<”, “>=”,“<=”,“like”和“rlike”

分層采樣

數據集分層抽取一定比例或者一定數據的隨機樣本

參數設置

參數框

stratified_sample_colstratified_sample_param

  • 下拉框選擇分組列(最大支持100個分組)
  • 可手動輸入分組的采樣個數(或者采樣比例)
  • 可配置隨機數種子,默認1234567
  • 可以自己配置並發計算核心數目與內存,默認係統自動分配

pai 命令

  1. PAI -name StratifiedSample -project algo_public
  2. -DinputTableName="test_input"
  3. -DoutputTableName="test_output"
  4. -DstrataColName="label"
  5. -DsampleSize="A:200,B:300,C:500"
  6. -DrandomSeed=1007
  7. -Dlifecycle=30

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表 - -
inputTablePartitions 可選,訓練輸入表分區。 - 默認選中全表
outputTableName 必選,輸出表 - -
strataColName 必選,層次列,分層就是按照此列作為key分層的 - -
sampleSize 可選,采樣大小,整數時:表示每個stratum的采樣個數;字符串時:格式為strata0:n0,strata1:n1 表示每個stratum分別配置采樣個數 - -
sampleRatio 可選,采樣比例,數字時:範圍(0,1)表示每個stratum的采樣比例;字符串時:格式為strata0:r0,strata1:r1 表示每個stratum分別配置采樣比例。 - -
randomSeed 可選, 隨機種子 - 默認123456
lifecycle 可選,輸出表生命周期 - 默認不設置
coreNum 可選,核心個數 - 默認不設置,係統自動分配
memSizePerCore 可選,單個核心使用的內存數 - 默認不設置,係統自動分配

注:當sampleSize 與 sampleRatio都為空時,報錯; 當sampleSize 與 sampleRatio都不為空時,以sampleSize為準。

示例

源數據
id outlook temperature humidity windy play
0 Sunny 85 85 false No
1 Sunny 80 90 true No
2 Overcast 83 86 false Yes
3 Rainy 70 96 false Yes
4 Rainy 68 80 false Yes
5 Rainy 65 70 true No
6 Overcast 64 65 true Yes
7 Sunny 72 95 false No
8 Sunny 69 70 false Yes
9 Rainy 75 80 false Yes
10 Sunny 75 70 true Yes
11 Overcast 72 90 true Yes
12 Overcast 81 75 false Yes
13 Rainy 71 91 true No
1. 創建實驗

stratified_sampling_demo_exp

2. 選取分組列

stratified_sampling_demo_exp_select_strata_column

  • 選擇play列,做為分組列
3. 配置采樣個數

stratified_sampling_demo_exp_config_param

  • play=Yes的分組采4條;play=No有分組采3條
4. 采樣結果

stratified_sampling_demo_exp_result


join

兩張表通過關聯信息,合成一張表,並決定輸出的字段;與SQL的join語句功能類似

參數設置

填寫參數screenshot

  • 連接類型支持:左連接,內連接,右連接,全連接
  • 關聯條件目前隻支持等式
  • 可手動添加或刪除關聯條件

PAI 命令

不提供pai命令


合並列

將兩張表的數據按列合並,需要表的行數保持一致

參數設置

如圖:screenshot左表選擇輸入列screenshot右表選擇輸入列screenshot

  • 選擇的兩張表行數需保持一致

  • 左表與右表選擇的輸出列名不能重複

  • 選擇輸出字段列時可手動更改輸出字段名

  • 若左表右表均不選擇輸出列,則默認輸出全表。此時勾選‘是否自動重命名輸出列’,會將重複列重命名後輸出

PAI 命令

  1. PAI -name AppendColumns -project algo_public -DoutputTableColNames="petal_length,petal_width,petal_length2,petal_width2"
  2. -DautoRenameCol="false" -DoutputTableName="pai_temp_770_6840_1" -DinputTableNames="iris_twopartition,iris_twopartition"
  3. -DinputPartitionsInfoList="dt=20150125/dp=20150124;dt=20150124/dp=20150123"
  4. -DselectedColNamesList="petal_length,petal_width;sepal_length,sepal_width";
  • name: 組件名字
  • project: project名字,用於指定算法所在空間。係統默認是algo_public,用戶自己更改後係統會報錯
  • outputTableColNames: 新表中各列的列名。逗號分隔,如果autoRenameCol為true,則此參數無效
  • autoRenameCol: (可選)輸出表是否自動重命名列,true為重命名,false不進行重命名,默認false
  • outputTableName: 輸出的表名
  • inputTableNames:輸入的表名,如果有多個,逗號分隔
  • inputPartitionsInfoList:(可選)輸入表對應選擇的partition列表,同一個表的各partition按逗號分隔,不同表的partition分號分隔
  • selectedColNamesList:選擇輸入的列名,同張表之間列名用逗號分隔,不同表之間用分號分隔

UNION

將兩張表的數據按行合並,左表及右表選擇輸出的字段個數以及類型應保持一致。整合了union和union all的功能。

參數設置

調整參數,如下:screenshot

  • 進行聯合操作時,左右表選擇的列數需相同,對應列的類型需保證一致
  • 可根據實際情況在條件框中手動輸入已選字段的過濾條件,默認情況下全表,目前操作符支持”=”,”!=”,”>”,”<”, “>=”,“<=”,“like” 和 “rlike”
  • 係統默認勾選去重。勾選後將會對生成的數據表的重複行進行去重操作(distinct)左表聯合列screenshot右表聯合列screenshot

PAI 命令

不提供pai命令


增加序號列

在數據表第一列追加ID列,並將append id後的內容存為新表

參數設置

PAI命令

  1. PAI -name AppendId -project algo_public -DIDColName="append_id" -DoutputTableName="test_11" -DinputTableName="bank_data"
  2. -DselectedColNames="age,campaign,cons_conf_idx,cons_price_idx,emp_var_rate,euribor3m,nr_employed,pdays,poutcome,previous,y";
  • name: 組件名字
  • project: project名字,用於指定算法所在空間。係統默認是algo_public,用戶自己更改後係統會報錯
  • IDColName:追加的ID列列名,從0開始編號,依次為0,1,2,3…
  • outputTableNames: 輸出表的名字
  • inputTableNmae: 輸入表的名字
  • selectedColNames: 要保留的字段名,多個用逗號分隔

拆分

背景

  • 對輸入表或分區進行按比例拆分,分別寫入兩張輸出表。

算法組件

split_icon_introsplig_param_setting

  • 拆分組件,對應兩個輸出樁
  • 如圖所示配置0.6,則左邊的輸出樁對應60%的數據,右邊對應40%的數據

PAI命令

  1. pai -name split -project algo_public
  2. -DinputTableName=wbpc
  3. -Doutput1TableName=wpbc_split1
  4. -Doutput2TableName=wpbc_split2
  5. -Dfraction=0.25;

參數設置

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表的表名 - -
inputTablePartitions 可選,輸入表中指定哪些分區參與訓練,格式為: partition_name=value。如果是多級,格式為name1=value1/name2=value2;如果指定多個分區,中間用’,’分開 - 輸入表的所有partition
output1TableName 必選,輸出結果表1 - -
output1TablePartition 可選,輸出結果表1分區名 - 輸出表1為非分區表
output2TableName 必選,輸出結果表2 - -
output2TablePartition 可選,輸出結果表2分區名 - 輸出表2為非分區表
fraction 必選,切分至輸出表1的數據比例 (0,1) -
lifecycle 可選,指定輸出表生命周期 正整數,[1,3650] 輸出表沒有生命周期

缺失值填充

缺失值填充用來將空值或者一個指定的值替換為最大值,最小值,均值或者一個自定義的值。可以通過給定一個缺失值的配置列表,來實現將輸入表的缺失值用指定的值來填充。

  • 可以將數值型的空值替換為最大值,最小值,均值或者一個自定義的值
  • 可以將字符型的空值,空字符串,空值和空字符串,指定值替換為一個自定義的值
  • 待填充的缺失值可以選擇空值或空字符,也可以自定義
  • 缺失值若選擇空字符,則填充的目標列應是string型
  • 數值型替換可以自定義,也可以直接選擇替換成數值最大值,最小值或者均值

缺失值填充界麵

image

兩個輸入樁依次對應參數為:

  • inputTableName 輸入表,即要填充的表

  • inputParaTableName 配置輸入表,即缺失值填充節點生成的參數列表,通過此參數,可以將一張表的配置參數應用到一張新的表

兩個輸出樁依次對應參數為:

  • outputTableName 輸出表,即填充完成的表

  • outputParaTableName 輸出配置表,用於應用到其他的數據集上

缺失值填充參數界麵

image

  • 填充的字段,原值,替換為三個部分組成了config參數,分別對應config參數的三個部分:列名,原值,替換值

PAI 命令

  1. PAI -name FillMissingValues -project algo_public -Dconfigs="poutcome,null-empty,testing"
  2. -DoutputTableName="test_3" -DinputPartitions="pt=20150501" -DinputTableName="bank_data_partition";

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表 - -
inputTablePartitions 可選,訓練輸入表分區。 - 默認選中全表
outputTableName 必選,輸出表 - -
configs 必選,缺失值填充的配置。格式如 “col1, null, 3.14; col2, empty, hello; col3, empty-null, world”,其中null表示空值,empty表示空字符。缺失值若選擇空字符,則填充的目標列應是string型。若采用最大值、最小值、均值,可以采用變量,其命名規範形如:min, max, mean。若用戶自定義替換值,則使用user-defined,格式如”col4,user-defined,str,str123” - -
outputParaTableName 必選,配置輸出表 - -
inputParaTableName 可選,配置輸入表 - 默認不輸入
lifecycle 可選,輸出表生命周期 - 默認不設置
coreNum 可選,核心個數 - 默認不設置,係統自動分配
memSizePerCore 可選,單個核心使用的內存數 - 默認不設置,係統自動分配

實例

測試數據

新建數據SQL

  1. drop table if exists fill_missing_values_test_input;
  2. create table fill_missing_values_test_input(
  3. col_string string,
  4. col_bigint bigint,
  5. col_double double,
  6. col_boolean boolean,
  7. col_datetime datetime);
  8. insert overwrite table fill_missing_values_test_input
  9. select
  10. *
  11. from
  12. (
  13. select
  14. '01' as col_string,
  15. 10 as col_bigint,
  16. 10.1 as col_double,
  17. True as col_boolean,
  18. cast('2016-07-01 10:00:00' as datetime) as col_datetime
  19. from dual
  20. union all
  21. select
  22. cast(null as string) as col_string,
  23. 11 as col_bigint,
  24. 10.2 as col_double,
  25. False as col_boolean,
  26. cast('2016-07-02 10:00:00' as datetime) as col_datetime
  27. from dual
  28. union all
  29. select
  30. '02' as col_string,
  31. cast(null as bigint) as col_bigint,
  32. 10.3 as col_double,
  33. True as col_boolean,
  34. cast('2016-07-03 10:00:00' as datetime) as col_datetime
  35. from dual
  36. union all
  37. select
  38. '03' as col_string,
  39. 12 as col_bigint,
  40. cast(null as double) as col_double,
  41. False as col_boolean,
  42. cast('2016-07-04 10:00:00' as datetime) as col_datetime
  43. from dual
  44. union all
  45. select
  46. '04' as col_string,
  47. 13 as col_bigint,
  48. 10.4 as col_double,
  49. cast(null as boolean) as col_boolean,
  50. cast('2016-07-05 10:00:00' as datetime) as col_datetime
  51. from dual
  52. union all
  53. select
  54. '05' as col_string,
  55. 14 as col_bigint,
  56. 10.5 as col_double,
  57. True as col_boolean,
  58. cast(null as datetime) as col_datetime
  59. from dual
  60. ) tmp;

輸入數據說明

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 04 | 13 | 10.4 | NULL | 2016-07-05 10:00:00 |
  5. | 02 | NULL | 10.3 | true | 2016-07-03 10:00:00 |
  6. | 03 | 12 | NULL | false | 2016-07-04 10:00:00 |
  7. | NULL | 11 | 10.2 | false | 2016-07-02 10:00:00 |
  8. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 |
  9. | 05 | 14 | 10.5 | true | NULL |
  10. +------------+------------+------------+-------------+--------------+

運行命令

  1. drop table if exists fill_missing_values_test_input_output;
  2. drop table if exists fill_missing_values_test_input_model_output;
  3. PAI -name FillMissingValues
  4. -project algo_public
  5. -Dconfigs="col_double,null,mean;col_string,null-empty,str_type_empty;col_bigint,null,max;col_boolean,null,true;col_datetime,null,2016-07-06 10:00:00"
  6. -DoutputParaTableName="fill_missing_values_test_input_model_output"
  7. -Dlifecycle="28"
  8. -DoutputTableName="fill_missing_values_test_input_output"
  9. -DinputTableName="fill_missing_values_test_input";
  10. drop table if exists fill_missing_values_test_input_output_using_model;
  11. drop table if exists fill_missing_values_test_input_output_using_model_model_output;
  12. PAI -name FillMissingValues
  13. -project algo_public
  14. -DoutputParaTableName="fill_missing_values_test_input_output_using_model_model_output"
  15. -DinputParaTableName="fill_missing_values_test_input_model_output"
  16. -Dlifecycle="28"
  17. -DoutputTableName="fill_missing_values_test_input_output_using_model"
  18. -DinputTableName="fill_missing_values_test_input";

運行結果

fill_missing_values_test_input_output

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 04 | 13 | 10.4 | true | 2016-07-05 10:00:00 |
  5. | 02 | 14 | 10.3 | true | 2016-07-03 10:00:00 |
  6. | 03 | 12 | 10.3 | false | 2016-07-04 10:00:00 |
  7. | str_type_empty | 11 | 10.2 | false | 2016-07-02 10:00:00 |
  8. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 |
  9. | 05 | 14 | 10.5 | true | 2016-07-06 10:00:00 |
  10. +------------+------------+------------+-------------+--------------+

fill_missing_values_test_input_model_output

  1. +------------+------------+
  2. | feature | json |
  3. +------------+------------+
  4. | col_string | {"name": "fillMissingValues", "type": "string", "paras":{"missing_value_type": "null-empty", "replaced_value": "str_type_empty"}} |
  5. | col_bigint | {"name": "fillMissingValues", "type": "bigint", "paras":{"missing_value_type": "null", "replaced_value": 14}} |
  6. | col_double | {"name": "fillMissingValues", "type": "double", "paras":{"missing_value_type": "null", "replaced_value": 10.3}} |
  7. | col_boolean | {"name": "fillMissingValues", "type": "boolean", "paras":{"missing_value_type": "null", "replaced_value": 1}} |
  8. | col_datetime | {"name": "fillMissingValues", "type": "datetime", "paras":{"missing_value_type": "null", "replaced_value": 1467770400000}} |
  9. +------------+------------+

fill_missing_values_test_input_output_using_model

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 04 | 13 | 10.4 | true | 2016-07-05 10:00:00 |
  5. | 02 | 14 | 10.3 | true | 2016-07-03 10:00:00 |
  6. | 03 | 12 | 10.3 | false | 2016-07-04 10:00:00 |
  7. | str_type_empty | 11 | 10.2 | false | 2016-07-02 10:00:00 |
  8. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 |
  9. | 05 | 14 | 10.5 | true | 2016-07-06 10:00:00 |
  10. +------------+------------+------------+-------------+--------------+

fill_missing_values_test_input_output_using_model_model_output

  1. +------------+------------+
  2. | feature | json |
  3. +------------+------------+
  4. | col_string | {"name": "fillMissingValues", "type": "string", "paras":{"missing_value_type": "null-empty", "replaced_value": "str_type_empty"}} |
  5. | col_bigint | {"name": "fillMissingValues", "type": "bigint", "paras":{"missing_value_type": "null", "replaced_value": 14}} |
  6. | col_double | {"name": "fillMissingValues", "type": "double", "paras":{"missing_value_type": "null", "replaced_value": 10.3}} |
  7. | col_boolean | {"name": "fillMissingValues", "type": "boolean", "paras":{"missing_value_type": "null", "replaced_value": 1}} |
  8. | col_datetime | {"name": "fillMissingValues", "type": "datetime", "paras":{"missing_value_type": "null", "replaced_value": 1467770400000}} |
  9. +------------+------------+

歸一化

  • 對一個表的某一列或多列,進行歸一化處理,產生的數據存入新表中。
  • 目前支持的是線性函數轉換,表達式如下:y=(x-MinValue)/(MaxValue-MinValue),MaxValue、MinValue分別為樣本的最大值和最小值。
  • 可以選擇是否保留原始列,勾選後原始列會被保留,處理過的列重命名。
  • 點擊選擇字段按鈕可以選擇想要歸一化的列,目前支持double類型與bigint類型。

歸一化界麵

image

兩個輸入樁依次對應參數為:

  • inputTableName 輸入表,即要歸一化的表

  • inputParaTableName 配置輸入表,即歸一化節點生成的參數列表,通過此參數,可以將一張表的配置參數應用到一張新的表

兩個輸出樁依次對應參數為:

  • outputTableName 輸出表,即歸一化完成的表

  • outputParaTableName 輸出配置表,用於應用到其他的數據集上

歸一化參數界麵

image

  • 保留原始列對應參數keepOriginal

PAI 命令

  1. PAI -name Normalize -project algo_public -DkeepOriginal="true" -DoutputTableName="test_4" -DinputPartitions="pt=20150501"
  2. -DinputTableName="bank_data_partition" -DselectedColNames="emp_var_rate,euribor3m";

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表 - -
selectedColNames 可選,輸入表選擇列 - 默認選中全部列
inputTablePartitions 可選,訓練輸入表分區。 - 默認選中全表
outputTableName 必選,輸出表 - -
outputParaTableName 必選,配置輸出表 - -
inputParaTableName 可選,配置輸入表 - 默認不輸入
keepOriginal 可選,是否保留原始列(keepOriginal =true時,處理過的列重命名(”normalized_”前綴),原始列保留,keepOriginal=false時,全部列保留且不重命名) - 默認為false
lifecycle 可選,輸出表生命周期 - 默認不設置
coreNum 可選,核心個數 - 默認不設置,係統自動分配
memSizePerCore 可選,單個核心使用的內存數 - 默認不設置,係統自動分配

實例

測試數據

新建數據SQL

  1. drop table if exists normalize_test_input;
  2. create table normalize_test_input(
  3. col_string string,
  4. col_bigint bigint,
  5. col_double double,
  6. col_boolean boolean,
  7. col_datetime datetime);
  8. insert overwrite table normalize_test_input
  9. select
  10. *
  11. from
  12. (
  13. select
  14. '01' as col_string,
  15. 10 as col_bigint,
  16. 10.1 as col_double,
  17. True as col_boolean,
  18. cast('2016-07-01 10:00:00' as datetime) as col_datetime
  19. from dual
  20. union all
  21. select
  22. cast(null as string) as col_string,
  23. 11 as col_bigint,
  24. 10.2 as col_double,
  25. False as col_boolean,
  26. cast('2016-07-02 10:00:00' as datetime) as col_datetime
  27. from dual
  28. union all
  29. select
  30. '02' as col_string,
  31. cast(null as bigint) as col_bigint,
  32. 10.3 as col_double,
  33. True as col_boolean,
  34. cast('2016-07-03 10:00:00' as datetime) as col_datetime
  35. from dual
  36. union all
  37. select
  38. '03' as col_string,
  39. 12 as col_bigint,
  40. cast(null as double) as col_double,
  41. False as col_boolean,
  42. cast('2016-07-04 10:00:00' as datetime) as col_datetime
  43. from dual
  44. union all
  45. select
  46. '04' as col_string,
  47. 13 as col_bigint,
  48. 10.4 as col_double,
  49. cast(null as boolean) as col_boolean,
  50. cast('2016-07-05 10:00:00' as datetime) as col_datetime
  51. from dual
  52. union all
  53. select
  54. '05' as col_string,
  55. 14 as col_bigint,
  56. 10.5 as col_double,
  57. True as col_boolean,
  58. cast(null as datetime) as col_datetime
  59. from dual
  60. ) tmp;

輸入數據說明

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 |
  5. | NULL | 11 | 10.2 | false | 2016-07-02 10:00:00 |
  6. | 02 | NULL | 10.3 | true | 2016-07-03 10:00:00 |
  7. | 03 | 12 | NULL | false | 2016-07-04 10:00:00 |
  8. | 04 | 13 | 10.4 | NULL | 2016-07-05 10:00:00 |
  9. | 05 | 14 | 10.5 | true | NULL |
  10. +------------+------------+------------+-------------+--------------+

運行命令

  1. drop table if exists normalize_test_input_output;
  2. drop table if exists normalize_test_input_model_output;
  3. PAI -name Normalize
  4. -project algo_public
  5. -DoutputParaTableName="normalize_test_input_model_output"
  6. -Dlifecycle="28"
  7. -DoutputTableName="normalize_test_input_output"
  8. -DinputTableName="normalize_test_input"
  9. -DselectedColNames="col_double,col_bigint"
  10. -DkeepOriginal="true";
  11. drop table if exists normalize_test_input_output_using_model;
  12. drop table if exists normalize_test_input_output_using_model_model_output;
  13. PAI -name Normalize
  14. -project algo_public
  15. -DoutputParaTableName="normalize_test_input_output_using_model_model_output"
  16. -DinputParaTableName="normalize_test_input_model_output"
  17. -Dlifecycle="28"
  18. -DoutputTableName="normalize_test_input_output_using_model"
  19. -DinputTableName="normalize_test_input";

運行結果

normalize_test_input_output

  1. +------------+------------+------------+-------------+--------------+-----------------------+-----------------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime | normalized_col_bigint | normalized_col_double |
  3. +------------+------------+------------+-------------+--------------+-----------------------+-----------------------+
  4. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 | 0.0 | 0.0 |
  5. | NULL | 11 | 10.2 | false | 2016-07-02 10:00:00 | 0.25 | 0.2499999999999989 |
  6. | 02 | NULL | 10.3 | true | 2016-07-03 10:00:00 | NULL | 0.5000000000000022 |
  7. | 03 | 12 | NULL | false | 2016-07-04 10:00:00 | 0.5 | NULL |
  8. | 04 | 13 | 10.4 | NULL | 2016-07-05 10:00:00 | 0.75 | 0.7500000000000011 |
  9. | 05 | 14 | 10.5 | true | NULL | 1.0 | 1.0 |
  10. +------------+------------+------------+-------------+--------------+-----------------------+-----------------------+

normalize_test_input_model_output

  1. +------------+------------+
  2. | feature | json |
  3. +------------+------------+
  4. | col_bigint | {"name": "normalize", "type":"bigint", "paras":{"min":10, "max": 14}} |
  5. | col_double | {"name": "normalize", "type":"double", "paras":{"min":10.1, "max": 10.5}} |
  6. +------------+------------+

normalize_test_input_output_using_model

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 01 | 0.0 | 0.0 | true | 2016-07-01 10:00:00 |
  5. | NULL | 0.25 | 0.2499999999999989 | false | 2016-07-02 10:00:00 |
  6. | 02 | NULL | 0.5000000000000022 | true | 2016-07-03 10:00:00 |
  7. | 03 | 0.5 | NULL | false | 2016-07-04 10:00:00 |
  8. | 04 | 0.75 | 0.7500000000000011 | NULL | 2016-07-05 10:00:00 |
  9. | 05 | 1.0 | 1.0 | true | NULL |
  10. +------------+------------+------------+-------------+--------------+

normalize_test_input_output_using_model_model_output

  1. +------------+------------+
  2. | feature | json |
  3. +------------+------------+
  4. | col_bigint | {"name": "normalize", "type":"bigint", "paras":{"min":10, "max": 14}} |
  5. | col_double | {"name": "normalize", "type":"double", "paras":{"min":10.1, "max": 10.5}} |
  6. +------------+------------+

標準化

  • 對一個表的某一列或多列,進行標準化處理,產生的數據存入新表中。
  • 標準化所使用的公式 :(X - Mean)/(standard deviation)。
  • Mean:樣本平均值。
  • standard deviation:樣本標準偏差,針對從總體抽樣,利用樣本來計算總體偏差,為了使算出的值與總體水平更接近,就必須將算出的標準偏差的值適度放大,即,img
  • 樣本標準偏差公式:imgimg代表所采用的樣本X1,X2,…,Xn的均值。
  • 可以選擇是否保留原始列,勾選後原始列會被保留,處理過的列重命名
  • 點擊選擇字段按鈕可以選擇想要標準化的列,目前支持double類型與bigint類型

標準化界麵

image

兩個輸入樁依次對應參數為:

  • inputTableName 輸入表,即要標準化的表

  • inputParaTableName 配置輸入表,即標準化節點生成的參數列表,通過此參數,可以將一張表的配置參數應用到一張新的表

兩個輸出樁依次對應參數為:

  • outputTableName 輸出表,即標準化完成的表

  • outputParaTableName 輸出配置表,用於應用到其他的數據集上

標準化參數界麵

image

  • 保留原始列對應參數keepOriginal

PAI 命令

  1. PAI -name Standardize -project algo_public -DkeepOriginal="false" -DoutputTableName="test_5"
  2. -DinputPartitions="pt=20150501" -DinputTableName="bank_data_partition" -DselectedColNames="euribor3m,pdays";

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTableName 必選,輸入表 - -
selectedColNames 可選,輸入表選擇列 - 默認選中全部列
inputTablePartitions 可選,訓練輸入表分區。 - 默認選中全表
outputTableName 必選,輸出表 - -
outputParaTableName 必選,配置輸出表 - -
inputParaTableName 可選,配置輸入表 - 默認不輸入
keepOriginal 可選,是否保留原始列(keepOriginal =true時,處理過的列重命名(”stdized_”前綴),原始列保留,keepOriginal=false時,全部列保留且不重命名) - 默認為false
lifecycle 可選,輸出表生命周期 - 默認不設置
coreNum 可選,核心個數 - 默認不設置,係統自動分配
memSizePerCore 可選,單個核心使用的內存數 - 默認不設置,係統自動分配

實例

測試數據

新建數據SQL

  1. drop table if exists standardize_test_input;
  2. create table standardize_test_input(
  3. col_string string,
  4. col_bigint bigint,
  5. col_double double,
  6. col_boolean boolean,
  7. col_datetime datetime);
  8. insert overwrite table standardize_test_input
  9. select
  10. *
  11. from
  12. (
  13. select
  14. '01' as col_string,
  15. 10 as col_bigint,
  16. 10.1 as col_double,
  17. True as col_boolean,
  18. cast('2016-07-01 10:00:00' as datetime) as col_datetime
  19. from dual
  20. union all
  21. select
  22. cast(null as string) as col_string,
  23. 11 as col_bigint,
  24. 10.2 as col_double,
  25. False as col_boolean,
  26. cast('2016-07-02 10:00:00' as datetime) as col_datetime
  27. from dual
  28. union all
  29. select
  30. '02' as col_string,
  31. cast(null as bigint) as col_bigint,
  32. 10.3 as col_double,
  33. True as col_boolean,
  34. cast('2016-07-03 10:00:00' as datetime) as col_datetime
  35. from dual
  36. union all
  37. select
  38. '03' as col_string,
  39. 12 as col_bigint,
  40. cast(null as double) as col_double,
  41. False as col_boolean,
  42. cast('2016-07-04 10:00:00' as datetime) as col_datetime
  43. from dual
  44. union all
  45. select
  46. '04' as col_string,
  47. 13 as col_bigint,
  48. 10.4 as col_double,
  49. cast(null as boolean) as col_boolean,
  50. cast('2016-07-05 10:00:00' as datetime) as col_datetime
  51. from dual
  52. union all
  53. select
  54. '05' as col_string,
  55. 14 as col_bigint,
  56. 10.5 as col_double,
  57. True as col_boolean,
  58. cast(null as datetime) as col_datetime
  59. from dual
  60. ) tmp;

輸入數據說明

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 |
  5. | NULL | 11 | 10.2 | false | 2016-07-02 10:00:00 |
  6. | 02 | NULL | 10.3 | true | 2016-07-03 10:00:00 |
  7. | 03 | 12 | NULL | false | 2016-07-04 10:00:00 |
  8. | 04 | 13 | 10.4 | NULL | 2016-07-05 10:00:00 |
  9. | 05 | 14 | 10.5 | true | NULL |
  10. +------------+------------+------------+-------------+--------------+

運行命令

  1. drop table if exists standardize_test_input_output;
  2. drop table if exists standardize_test_input_model_output;
  3. PAI -name Standardize
  4. -project algo_public
  5. -DoutputParaTableName="standardize_test_input_model_output"
  6. -Dlifecycle="28"
  7. -DoutputTableName="standardize_test_input_output"
  8. -DinputTableName="standardize_test_input"
  9. -DselectedColNames="col_double,col_bigint"
  10. -DkeepOriginal="true";
  11. drop table if exists standardize_test_input_output_using_model;
  12. drop table if exists standardize_test_input_output_using_model_model_output;
  13. PAI -name Standardize
  14. -project algo_public
  15. -DoutputParaTableName="standardize_test_input_output_using_model_model_output"
  16. -DinputParaTableName="standardize_test_input_model_output"
  17. -Dlifecycle="28"
  18. -DoutputTableName="standardize_test_input_output_using_model"
  19. -DinputTableName="standardize_test_input";

運行結果

standardize_test_input_output

  1. +------------+------------+------------+-------------+--------------+--------------------+--------------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime | stdized_col_bigint | stdized_col_double |
  3. +------------+------------+------------+-------------+--------------+--------------------+--------------------+
  4. | 01 | 10 | 10.1 | true | 2016-07-01 10:00:00 | -1.2649110640673518 | -1.2649110640683832 |
  5. | NULL | 11 | 10.2 | false | 2016-07-02 10:00:00 | -0.6324555320336759 | -0.6324555320341972 |
  6. | 02 | NULL | 10.3 | true | 2016-07-03 10:00:00 | NULL | 0.0 |
  7. | 03 | 12 | NULL | false | 2016-07-04 10:00:00 | 0.0 | NULL |
  8. | 04 | 13 | 10.4 | NULL | 2016-07-05 10:00:00 | 0.6324555320336759 | 0.6324555320341859 |
  9. | 05 | 14 | 10.5 | true | NULL | 1.2649110640673518 | 1.2649110640683718 |
  10. +------------+------------+------------+-------------+--------------+--------------------+--------------------+

standardize_test_input_model_output

  1. +------------+------------+
  2. | feature | json |
  3. +------------+------------+
  4. | col_bigint | {"name": "standardize", "type":"bigint", "paras":{"mean":12, "std": 1.58113883008419}} |
  5. | col_double | {"name": "standardize", "type":"double", "paras":{"mean":10.3, "std": 0.1581138830082909}} |
  6. +------------+------------+

standardize_test_input_output_using_model

  1. +------------+------------+------------+-------------+--------------+
  2. | col_string | col_bigint | col_double | col_boolean | col_datetime |
  3. +------------+------------+------------+-------------+--------------+
  4. | 01 | -1.2649110640673515 | -1.264911064068383 | true | 2016-07-01 10:00:00 |
  5. | NULL | -0.6324555320336758 | -0.6324555320341971 | false | 2016-07-02 10:00:00 |
  6. | 02 | NULL | 0.0 | true | 2016-07-03 10:00:00 |
  7. | 03 | 0.0 | NULL | false | 2016-07-04 10:00:00 |
  8. | 04 | 0.6324555320336758 | 0.6324555320341858 | NULL | 2016-07-05 10:00:00 |
  9. | 05 | 1.2649110640673515 | 1.2649110640683716 | true | NULL |
  10. +------------+------------+------------+-------------+--------------+

standardize_test_input_output_using_model_model_output

  1. +------------+------------+
  2. | feature | json |
  3. +------------+------------+
  4. | col_bigint | {"name": "standardize", "type":"bigint", "paras":{"mean":12, "std": 1.58113883008419}} |
  5. | col_double | {"name": "standardize", "type":"double", "paras":{"mean":10.3, "std": 0.1581138830082909}} |
  6. +------------+------------+

類型轉換

組件功能介紹

  • 將表的字段類型轉成另一個類型

PAI 命令實例

  1. PAI -name type_transform
  2. -project algo_public
  3. -DinputTable="pai_dense"
  4. -DselectedCols="gail,loss,work_year"
  5. -Dpre_type="double"
  6. -Dnew_type="bigint"
  7. -DoutputTable="pai_temp_2250_20272_1"
  8. -Dlifecycle="28"

算法參數

參數名稱 參數描述 參數值可選項 默認值
inputTable 必選,輸入表的表名 - -
inputTablePartitions 可選,輸入表中指定哪些分區參與訓練,格式為: partition_name=value。如果是多級,格式為name1=value1/name2=value2;如果指定多個分區,中間用’,’分開 - 輸入表的所有partition
outputTable 必選,類型轉換的結果表 - -
selectedCols 必選,需要類型轉換特征列,必須是同一個類型 - -
pre_type 原字段類型,必須與selectedCols勾選的字段類型一致,否則會報字段類型不一致錯誤 - -
new_type 新的字段類型,用戶設置 100
lifecycle outputTable結果表生命周期,可選,默認7 7

使用DEMO

1. 拖拽一個讀數據表組件,配置數據表pai_dense結構如下

image

image

2. 拖拽一個類型轉換組件, 在右側參數配置欄中:勾選需要轉換的特征,比如下圖勾選了3個原數據類型為double的列(主要double類型必須與勾選的字段類型一致),轉換成bigint類型

image

image

3. 右鍵點擊運行後,可以看到輸出結果表字段類型變化如下

image

最後更新:2016-11-23 16:04:15

  上一篇:go 源/目標__使用手冊(new)_機器學習-阿裏雲
  下一篇:go 特征工程__使用手冊(new)_機器學習-阿裏雲