阅读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)_机器学习-阿里云