全部产品
Search
文档中心

人工智能平台 PAI:GBDT二分类

更新时间:Feb 27, 2024

GBDT(Gradient Boosting Decision Tree)二分类算法的原理是设置阈值,如果特征值大于阈值,则为正例,反之为负例。

组件配置

您可以使用以下任意一种方式,配置GBDT二分类组件参数。

方式一:可视化方式

Designer工作流页面配置组件参数。

页签

参数

描述

字段设置

选择特征列

输入数据源中,参与训练的特征列。支持DOUBLE及BIGINT类型。

说明

特征列数量不能超过800。

选择标签列

仅支持BIGINT类型。

选择分组列

支持DOUBLE及BIGINT类型,默认将全表作为一组。

参数设置

metric类型

支持NDCGDCG类型。

树的数目

取值范围为1~10000。

学习速率

取值范围为(0,1)

训练采集样本比例

取值范围为(0,1]

训练采集特征比例

取值范围为(0,1]

最大叶子数

取值范围为1~1000。

测试数据比例

取值范围为[0,1)

树最大深度

取值范围为1~100。

叶子点最少样本数

取值范围为1~1000。

随机数产生器种子

取值范围为[0,10]

一个特征分裂的最大数量

取值范围为1~1000。

执行调优

核数目

系统根据输入数据量,自动分配训练的实例数量。

内存

系统根据输入数据量,自动分配内存。取值范围为1024 MB~64*1024 MB。

方式二:PAI命令方式

使用PAI命令方式,配置该组件参数。您可以使用SQL脚本组件进行PAI命令调用,详情请参见SQL脚本

PAI -name gbdt_lr
    -project algo_public
    -DfeatureSplitValueMaxSize="500"
    -DrandSeed="0"
    -Dshrinkage="0.5"
    -DmaxLeafCount="32"
    -DlabelColName="y"
    -DinputTableName="bank_data_partition"
    -DminLeafSampleCount="500"
    -DgroupIDColName="nr_employed"
    -DsampleRatio="0.6"
    -DmaxDepth="11"
    -DmodelName="xlab_m_GBDT_LR_21208"
    -DmetricType="2"
    -DfeatureRatio="0.6"
    -DinputTablePartitions="pt=20150501"
    -DtestRatio="0.0"
    -DfeatureColNames="age,previous,cons_conf_idx,euribor3m"
    -DtreeCount="500"

参数

是否必选

描述

默认值

inputTableName

输入表的名称。

featureColNames

输入表中,用于训练的特征列名。

所有数值列

labelColName

输入表中的标签列名。

inputTablePartitions

输入表中,参与训练的分区。支持的格式包括:

  • Partition_name=value

  • name1=value1/name2=value2:多级分区

说明

如果指定多个分区,则使用英文逗号(,)分隔。

所有分区

modelName

输出的模型名称。

outputImportanceTableName

输出特征重要性的表名。

groupIDColName

数据分组列。

全表

lossType

损失函数类型为:4:LOG_LIKELIHOOD。

4

metricType

Metric包括以下类型:

  • 0:NDCG(Normalized Discounted Cumulative Gain)

  • 1:DCG(Discounted Cumulative Gain)

  • 2:AUC,仅适用于label取值为0/1的场景(弃用)

0

treeCount

树数量,取值范围为1~10000。

500

shrinkage

学习速率,取值范围为(0,1)

0.05

maxLeafCount

最大叶子数,取值范围为1~1000。

32

maxDepth

树的最大深度,取值范围为1~100。

10

minLeafSampleCount

叶子节点容纳的最少样本数,取值范围为1~1000。

500

sampleRatio

训练采集的样本比例,取值范围为(0,1]

0.6

featureRatio

训练采集的特征比例,取值范围为(0,1]

0.6

tau

GBRank Loss中的Tau参数,取值范围为[0,1]

0.6

p

GBRank Loss中的p参数,取值范围为[1,10]

1

randSeed

随机数种子,取值范围为[0,10]

0

newtonStep

使用Newton迭代法的开关,取值范围为{0,1}

1

featureSplitValueMaxSize

特征分裂的最大数量,取值范围为1~1000。

500

lifecycle

输出表的生命周期,单位为天。

说明
  • GBDT与GBDT_LR默认的损失函数类型不同。因为GBDT默认为regression loss:mean squared error loss,GBDT_LR默认为logistic regression loss,所以GBDT_LR无需手动配置损失函数,系统会自动配置损失函数。

  • GBDT的特征列、标签列及分组列仅支持数值类型。

  • 连接ROC曲线时,预测组件需要选择目标基准值。

示例

  1. 使用SQL语句,生成训练数据。

    drop table if exists gbdt_lr_test_input;
    create table gbdt_lr_test_input
    as
    select
        *
    from
    (
        select
            cast(1 as double) as f0,
            cast(0 as double) as f1,
            cast(0 as double) as f2,
            cast(0 as double) as f3,
            cast(0 as bigint) as label
        from dual
        union all
            select
                cast(0 as double) as f0,
                cast(1 as double) as f1,
                cast(0 as double) as f2,
                cast(0 as double) as f3,
                cast(0 as bigint) as label
        from dual
        union all
            select
                cast(0 as double) as f0,
                cast(0 as double) as f1,
                cast(1 as double) as f2,
                cast(0 as double) as f3,
                cast(1 as bigint) as label
        from dual
        union all
            select
                cast(0 as double) as f0,
                cast(0 as double) as f1,
                cast(0 as double) as f2,
                cast(1 as double) as f3,
                cast(1 as bigint) as label
        from dual
        union all
            select
                cast(1 as double) as f0,
                cast(0 as double) as f1,
                cast(0 as double) as f2,
                cast(0 as double) as f3,
                cast(0 as bigint) as label
        from dual
        union all
            select
                cast(0 as double) as f0,
                cast(1 as double) as f1,
                cast(0 as double) as f2,
                cast(0 as double) as f3,
                cast(0 as bigint) as label
        from dual
    ) a;

    生成的训练数据表gbdt_lr_test_input如下。

    f0

    f1

    f2

    f3

    label

    1.0

    0.0

    0.0

    0.0

    0

    0.0

    0.0

    1.0

    0.0

    1

    0.0

    0.0

    0.0

    1.0

    1

    0.0

    1.0

    0.0

    0.0

    0

    1.0

    0.0

    0.0

    0.0

    0

    0.0

    1.0

    0.0

    0.0

    0

  2. 使用PAI命令,提交GBDT二分类组件的训练参数。

    drop offlinemodel if exists gbdt_lr_test_model;
    PAI -name gbdt_lr
        -project algo_public
        -DfeatureSplitValueMaxSize="500"
        -DrandSeed="1"
        -Dshrinkage="1"
        -DmaxLeafCount="30"
        -DlabelColName="label"
        -DinputTableName="gbdt_lr_test_input"
        -DminLeafSampleCount="1"
        -DsampleRatio="1"
        -DmaxDepth="10"
        -DmodelName="gbdt_lr_test_model"
        -DmetricType="0"
        -DfeatureRatio="1"
        -DtestRatio="0"
        -DfeatureColNames="f0,f1,f2,f3"
        -DtreeCount="5"
  3. 使用PAI命令,提交预测组件参数。

    drop table if exists gbdt_lr_test_prediction_result;
    PAI -name prediction
        -project algo_public
        -DdetailColName="prediction_detail"
        -DmodelName="gbdt_lr_test_model"
        -DitemDelimiter=","
        -DresultColName="prediction_result"
        -Dlifecycle="28"
        -DoutputTableName="gbdt_lr_test_prediction_result"
        -DscoreColName="prediction_score"
        -DkvDelimiter=":"
        -DinputTableName="gbdt_lr_test_input"
        -DenableSparse="false"
        -DappendColNames="label";
  4. 查看预测结果表gbdt_lr_test_prediction_result

    label

    prediction_result

    prediction_score

    prediction_detail

    0

    0

    0.9984308925552831

    {“0”: 0.9984308925552831, “1”: 0.001569107444716943}

    0

    0

    0.9984308925552831

    {“0”: 0.9984308925552831, “1”: 0.001569107444716943}

    1

    1

    0.9982721832240973

    {“0”: 0.001727816775902724, “1”: 0.9982721832240973}

    1

    1

    0.9982721832240973

    {“0”: 0.001727816775902724, “1”: 0.9982721832240973}

    0

    0

    0.9984308925552831

    {“0”: 0.9984308925552831, “1”: 0.001569107444716943}

    0

    0

    0.9984308925552831

    {“0”: 0.9984308925552831, “1”: 0.001569107444716943}