RandomNodeSplit
¶
RandomNodeSplit(
split: Literal["train_rest", "test_rest", "random"] = "train_rest",
num_val: Union[int, float] = 500,
num_test: Union[int, float] = 1000,
num_train_per_class: int = 20,
key: str = "node_labels",
)
Bases: BaseTransform
Randomly splits the nodes of a graph into training, validation and test
sets, stored as the boolean masks train_mask, val_mask and
test_mask of shape [num_nodes].
Randomness comes from mx.random.permutation, so results are
reproducible with mx.random.seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
split
|
Literal['train_rest', 'test_rest', 'random']
|
The type of split:
Default: |
'train_rest'
|
num_val
|
Union[int, float]
|
Number of validation nodes, or ratio of the nodes if given as
a float. Default: |
500
|
num_test
|
Union[int, float]
|
Number of test nodes, or ratio of the nodes if given as a
float. Default: |
1000
|
num_train_per_class
|
int
|
Number of training nodes per class for the
|
20
|
key
|
str
|
Name of the attribute holding the class index of each node, used
by the |
'node_labels'
|
Example:
graph = GraphData(
edge_index=mx.array([[0, 1, 2, 3], [1, 2, 3, 4]]),
node_features=mx.ones((5, 2)),
)
graph = RandomNodeSplit(num_val=1, num_test=0.2)(graph)
graph.train_mask
# e.g. mx.array([True, False, True, False, True])
Methods:
| Name | Description |
|---|---|
process |
Adds the |
Source code in mlx_graphs/transforms/splits.py
process
¶
Adds the train_mask, val_mask and test_mask attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to split. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with the three masks. |
Source code in mlx_graphs/transforms/splits.py
from mlx_graphs.transforms import RandomNodeSplit · mlx_graphs/transforms/splits.py