Skip to content

AmazonDataset

AmazonDataset(
    name: AMAZON_NAMES,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: _NPZDataset

The Amazon Computers and Amazon Photo co-purchase graphs from the "Pitfalls of Graph Neural Network Evaluation" paper.

Nodes are products, edges connect products that are frequently bought together, node features are bag-of-words of the product reviews and the task is to predict the product category.

The datasets come without train/validation/test split; create one with e.g. RandomNodeSplit.

Parameters:

Name Type Description Default
name AMAZON_NAMES

"computers" (13,752 nodes, 491,722 edges, 767 features, 10 classes) or "photo" (7,650 nodes, 238,162 edges, 745 features, 8 classes).

required
base_dir Optional[str]

Directory where to store dataset files. Default is in the local directory .mlx_graphs_data/.

None
pre_transform Optional[Callable]

A function/transform applied to the graph once, before it is saved.

None
transform Optional[Callable]

A function/transform applied to the graph at every access.

None

Example:

from mlx_graphs.datasets import AmazonDataset

dataset = AmazonDataset("computers")
>>> amazon_computers(num_graphs=1)

dataset[0]
>>> GraphData(
        edge_index(shape=(2, 491722), int32)
        node_features(shape=(13752, 767), float32)
        node_labels(shape=(13752,), int32))
Source code in mlx_graphs/datasets/npz_dataset.py
def __init__(
    self,
    name: AMAZON_NAMES,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    assert name.lower() in get_args(AMAZON_NAMES), "Invalid dataset name"
    super().__init__(name, base_dir, pre_transform, transform)

from mlx_graphs.datasets import AmazonDataset · mlx_graphs/datasets/npz_dataset.py