简体   繁体   English

Stellargraph 无法使用数据洗牌

[英]Stellargraph failing to work with data shuffle

when I ran the StellarGraph's demo on graph classification using DGCNNs, I got the same result as in the demo.当我使用 DGCNN 运行 StellarGraph 关于图形分类的演示时,我得到了与演示中相同的结果。

However, when I tested what happens when I first shuffle the data using the following code:但是,当我使用以下代码测试第一次对数据进行洗牌时会发生什么:

shuffler = list(zip(graphs, graph_labels))
random.shuffle(shuffler)
graphs, graph_labels = zip(*shuffler)

The model didn't learn at all (accuracy of around 50% - just as data distribution). model 根本没有学习(准确度约为 50% - 就像数据分布一样)。

Does anyone know why this happens?有谁知道为什么会这样? Maybe I shuffled in a wrong way?也许我以错误的方式洗牌? Or is it that the data should be unshuffled in the first place (also why? it doesn't make any sense)?还是首先应该对数据进行非洗牌(为什么?这没有任何意义)? Or is it a bug in StellarGraph's implementation?或者它是 StellarGraph 实现中的一个错误?

I found the problem.我发现了问题。 It wasn't anything to do with the shuffling algorithm, nor with StellarGraph's implementation.这与洗牌算法无关,也与 StellarGraph 的实现无关。 The problem was in the demo, at the following lines:问题出在演示中,在以下几行:

train_gen = gen.flow(
    list(train_graphs.index - 1),
    targets=train_graphs.values,
    batch_size=50,
    symmetric_normalization=False,
)

test_gen = gen.flow(
    list(test_graphs.index - 1),
    targets=test_graphs.values,
    batch_size=1,
    symmetric_normalization=False,
)

The problem was caused, specifically by train_graphs.index - 1 and test_graphs.index - 1 .问题是由 train_graphs.index - train_graphs.index - 1test_graphs.index - 1引起的。 The indices are already in the range between 0 to n , so subtructing one from them would cause the graph data to "shift" one backwards, causing each data point to get the label of a different data point.索引已经在0n之间的范围内,因此从中减去一个会导致图形数据向后“移动”一个,从而导致每个数据点获得不同数据点的 label。

To fix this, simply change them to train_graphs.index and test_graphs.index without the -1 at the end.要解决这个问题,只需将它们更改为train_graphs.indextest_graphs.index ,最后不带-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM