AsLinkPredDataset

class dgl.data.AsLinkPredDataset(dataset, split_ratio=None, neg_ratio=3, **kwargs)[source]

Bases: DGLDataset

将数据集重新用于链接预测任务。

创建的数据集将包含链接预测所需的数据。 目前仅支持同构图。 它将仅保留提供的数据集中的第一个图,并根据给定的分割比例生成训练/验证/测试边, 以及基于neg_ratio的对应负边。生成的边将被缓存到磁盘以便快速重新加载。如果提供的分割比例与缓存的不同,它将适当地重新处理数据集。

Parameters:
  • dataset (DGLDataset) – The dataset to be converted.

  • split_ratio ((float, float, float), optional) – 训练集、验证集和测试集的分割比例。总和必须为一。

  • neg_ratio (int, optional) – 表示要采样的负样本数量 负样本的数量将等于或小于 neg_ratio * num_positive_edges。

feat_size

图中特征维度的大小

Type:

int

train_graph

用于训练的DGLGraph

Type:

DGLGraph

val_edges

验证集边缘,编码为 ((positive_edge_src, positive_edge_dst), (negative_edge_src, negative_edge_dst))

Type:

元组[元组[张量, 张量], 元组[张量, 张量]]

test_edges

测试集边缘,编码为 ((positive_edge_src, positive_edge_dst), (negative_edge_src, negative_edge_dst))

Type:

元组[元组[张量, 张量], 元组[张量, 张量]]

示例

>>> ds = dgl.data.CoraGraphDataset()
>>> print(ds)
Dataset("cora_v2", num_graphs=1, save_path=...)
>>> new_ds = dgl.data.AsLinkPredDataset(ds, [0.8, 0.1, 0.1])
>>> print(new_ds)
Dataset("cora_v2-as-linkpred", num_graphs=1, save_path=/home/ubuntu/.dgl/cora_v2-as-linkpred)
>>> print(hasattr(new_ds, "test_edges"))
True
__getitem__(idx)[source]

获取索引处的数据对象。

__len__()[source]

数据集中的示例数量。