3
$\begingroup$

Let's say I have a network that consists of a single weakly connected component. From various papers I've seen that if you want to use inductive GNNs like GraphSAGE, it is advisable to split your train/test data into two separate graphs or components.

Since I've seen that there are different approaches for node classification and link prediction tasks, I am specifically interested in node classification tasks, possible multiclass classification.

So the train/test split graphs would need to ensure some sort of reasonable class presence in both train and test graphs as well as avoid isolated nodes. I've seen some example where they simply use scikit train/test split, but to me it seems it disregards node connections and there is no guarantee you won't be left with isolated nodes that could skew results.

Could I use something as Louvain, to find communities of nodes, and then split the graph based on communities. In my mind, that would help with the structural integrity of the graph, or are there any better approaches?

$\endgroup$

4 Answers 4

3
+100
$\begingroup$

If I understood you correctly, you are looking to do a kind of stratified sampling, and would like to create the strata or clusters to perform train/ test splits over the identified "highly connected graphs".

One fundamental way would be to run a clustering algorithm to first identify the rich clusters and then perform a random test/ train split over each of the identified clusters. One of the main clustering algorithms that aligns with keeping the graphical integrity is spectral clustering. For implementation in scikit-learn refer this link.

$\endgroup$
2
$\begingroup$

One option would be using an existing package that is designed to train/test split graphs while maintaining class rates. For example, the PyG (PyTorch Geometric) package has RandomNodeSplit class which has a num_train_per_class argument.

$\endgroup$
1
  • $\begingroup$ if self.split == 'train_rest': perm = torch.randperm(num_nodes) val_mask[perm[:num_val]] = True test_mask[perm[num_val:num_val + num_test]] = True train_mask[perm[num_val + num_test:]] = True Taken from pytorch-geometric.readthedocs.io/en/latest/_modules/… Is this basically the same approach as I first mentioned, just do a random train/test split and don't worry about rels? I'll give you the bounty if you double check for me :) $\endgroup$ Commented Mar 10, 2022 at 19:09
2
$\begingroup$

I don't have a tone of experience in graph based ML applications, so correct me if I'm oversimplifying, but to restate the problem:

  • You have a graph of weakly connected nodes
  • You want to use GraphSAGE, which, based on my research, can batch graphs based on local regions, using depth as a hyperparameter
  • you want to balance for classes within the graph. So each node has a classification, and you want to learn that classification based on the content of that node, and the nodes in the local area
  • You don't want uselessly small regions, or completely isolated nodes, to wind up in your train or test set

So, with all things being equal, this approach seems like it would be a solution:

  • Iterate through your graph, defining which nodes qualify as a valid given the depth you're training GraphSAGE at and some criteria you define (there must be >5 nodes connected by depth 3, for instance)
  • based on those valid nodes, balance them based on class
  • use that balanced, filtered dataset to train your model

Again, I have limited experience, but it seems to me that if your graph is truly sparse, excessively preprocessing input would give your model a naive understanding of the problem you're working on, meaning your test results might be lackluster as your model is applied outside of the training space. So, while the above is potentially an answer to your question, I don't recommend the approach.

$\endgroup$
1
$\begingroup$

If you are using Pytorch geometric library, checkout https://pytorch-geometric.readthedocs.io/en/latest/modules/loader.html?highlight=ClusterData#torch_geometric.loader.ClusterData, it cluster data in the way you want and you can easily create subgraphs for training, validation and testing from a single graph. It's based on this paper: https://arxiv.org/abs/1905.07953. Here is example: https://colab.research.google.com/drive/1XAjcjRHrSR_ypCk_feIWFbcBKyT4Lirs?usp=sharing#scrollTo=zwhcs1L5fPjx

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.