标签传播分类为半监督的分类算法,原理为用已标记节点的标签信息去预测未标记节点的标签信息。本文为您介绍PAI-Designer(原PAI-Studio)提供的标签传播分类组件。
背景信息
标签传播分类算法的基本思路:在算法执行过程中,每个节点的标签按相似度传播给相邻节点,在节点传播的每一步,每个节点根据相邻节点的标签来更新自己的标签。与该节点相似度越大,其相邻节点对其标注的影响权值越大,相似节点的标签越趋于一致,其标签就越容易传播。在标签传播过程中,保持已标注数据的标签不变,使其像一个源头把标签传向未标注数据。最终,当迭代过程结束时,相似节点的概率分布也趋于相似,可以划分到同一个类别中,从而完成标签传播过程。
PAI-Designer(原PAI-Studio)支持通过可视化或PAI命令方式,配置标签传播分类组件的参数。
可视化方式
页签 | 参数 | 描述 |
---|---|---|
字段设置 | 顶点表:选择顶点列 | 点表的点所在列。 |
顶点表:选择标签列 | 点表的点的权重所在列。 | |
顶点表:选择权值列 | 边表的起点所在列。 | |
边表:选择源顶点列 | 边表的终点所在列。 | |
边表:选择目标顶点列 | 边表的终点所在列。 | |
边表:选择权值列 | 边表边的权重所在列。 | |
参数设置 | 最大迭代次数 | 可选,默认为30。 |
阻尼系数 | 默认为0.8。 | |
收敛系数 | 默认为0.000001。 | |
执行调优 | 进程数 | 作业并行执行的节点数。数字越大并行度越高,但是框架通讯开销会增大。 |
进程内存 | 单个作业可使用的最大内存量。系统默认为每个作业分配4096 MB内存,实际使用内存超过该值,会抛出OutOfMemory异常。 |
PAI命令方式
PAI -name LabelPropagationClassification
-project algo_public
-DinputEdgeTableName=LabelPropagationClassification_func_test_edge
-DfromVertexCol=flow_out_id
-DtoVertexCol=flow_in_id
-DinputVertexTableName=LabelPropagationClassification_func_test_node
-DvertexCol=node
-DvertexLabelCol=label
-DoutputTableName=LabelPropagationClassification_func_test_result
-DhasEdgeWeight=true
-DedgeWeightCol=edge_weight
-DhasVertexWeight=true
-DvertexWeightCol=label_weight
-Dalpha=0.8
-Depsilon=0.000001;
参数 | 是否必选 | 描述 | 默认值 |
---|---|---|---|
inputEdgeTableName | 是 | 输入边表名。 | 无 |
inputEdgeTablePartitions | 否 | 输入边表的分区。 | 全表读入 |
fromVertexCol | 是 | 输入边表的起点所在列。 | 无 |
toVertexCol | 是 | 输入边表的终点所在列。 | 无 |
inputVertexTableName | 是 | 输入点表名称。 | 无 |
inputVertexTablePartitions | 否 | 输入点表的分区。 | 全表读入 |
vertexCol | 是 | 输入点表的点所在列。 | 无 |
outputTableName | 是 | 输出表名。 | 无 |
outputTablePartitions | 否 | 输出表的分区。 | 无 |
lifecycle | 否 | 输出表的生命周期。 | 无 |
workerNum | 否 | 作业并行执行的节点数。数字越大并行度越高,但是框架通讯开销会增大。 | 未设置 |
workerMem | 否 | 单个作业可使用的最大内存量。系统默认为每个作业分配4096 MB内存,实际使用内存超过该值,会抛出OutOfMemory异常。 | 4096 |
splitSize | 否 | 数据切分大小。 | 64 |
hasEdgeWeight | 否 | 输入边表的边是否有权重。 | false |
edgeWeightCol | 否 | 输入边表边的权重所在列。 | 无 |
hasVertexWeight | 否 | 输入点表的点是否有权重。 | false |
vertexWeightCol | 否 | 输入点表的点的权重所在列。 | 无 |
alpha | 否 | 阻尼系数。 | 0.8 |
epsilon | 否 | 收敛系数。 | 0.000001 |
maxIter | 否 | 最大迭代次数。 | 30 |
使用示例
- 生成训练数据。
drop table if exists LabelPropagationClassification_func_test_edge; create table LabelPropagationClassification_func_test_edge as select * from ( select 'a' as flow_out_id, 'b' as flow_in_id, 0.2 as edge_weight from dual union all select 'a' as flow_out_id, 'c' as flow_in_id, 0.8 as edge_weight from dual union all select 'b' as flow_out_id, 'c' as flow_in_id, 1.0 as edge_weight from dual union all select 'd' as flow_out_id, 'b' as flow_in_id, 1.0 as edge_weight from dual )tmp ; drop table if exists LabelPropagationClassification_func_test_node; create table LabelPropagationClassification_func_test_node as select * from ( select 'a' as node,'X' as label, 1.0 as label_weight from dual union all select 'd' as node,'Y' as label, 1.0 as label_weight from dual )tmp;
对应的图结构如下所示。 - 查看训练结果。
+------+-----+------------+ | node | tag | weight | +------+-----+------------+ | a | X | 1.0 | | b | X | 0.16667 | | b | Y | 0.83333 | | c | X | 0.53704 | | c | Y | 0.46296 | | d | Y | 1.0 | +------+-----+------------+