Home / Academy / Point of Sale & Retail / Graph Neural Networks for Product Affinity Discovery in Point-of-Sale Transaction Data
Point of Sale & RetailAdvanced10 min read

Graph Neural Networks for Product Affinity Discovery in Point-of-Sale Transaction Data

Model products as nodes and co-purchases as edges, using GNN architectures to discover complex affinity structures beyond pairwise association rules.

Key Takeaways

  • Traditional market basket analysis based on pairwise association rules (support, confidence, lift) captures only direct co-purchase relationships and misses higher-order product affinity structures.
  • Graph neural networks operating on product co-purchase graphs learn distributed representations that encode multi-hop affinity patterns, enabling more nuanced cross-selling and assortment recommendations.
  • The product co-purchase graph constructed from PoS data naturally captures temporal dynamics when edges are weighted by recency, reflecting evolving consumer preferences rather than static historical patterns.

Limitations of Pairwise Association Rules

Market basket analysis, pioneered by Agrawal, Imielinski, and Swami (1993), has been a foundational technique in retail analytics for three decades. The Apriori algorithm and its successors efficiently mine frequent itemsets from transaction data and derive association rules characterized by support (frequency of co-occurrence), confidence (conditional probability of purchasing item B given item A), and lift (the ratio of observed co-purchase frequency to expected frequency under independence). These pairwise metrics have supported countless cross-selling and product placement decisions. However, pairwise analysis has fundamental limitations that become apparent as retailers seek more sophisticated product affinity insights. First, the number of potentially interesting item pairs grows quadratically with the product catalog size, creating a combinatorial explosion that makes comprehensive pairwise analysis unwieldy for stores with thousands of SKUs. Second, pairwise rules cannot capture transitive affinities: if product A is frequently purchased with product B, and product B with product C, pairwise analysis treats the A-C relationship independently even though the shared connection through B suggests an indirect affinity. Third, association rules provide no mechanism for learning latent product representations that generalize across similar items. askbiz.co extends beyond pairwise association analysis by constructing product affinity graphs that capture the full network structure of co-purchase relationships.

Constructing Product Co-Purchase Graphs

The first step toward graph-based product affinity analysis is constructing a graph from PoS transaction data. Each product (SKU or product group) becomes a node, and edges connect products that appear together in the same transaction. Edge weights encode the strength of the co-purchase relationship, typically measured by the number of transactions containing both products, the lift statistic (to adjust for base-rate popularity), or pointwise mutual information (PMI) which measures the degree to which co-purchase frequency exceeds the independence expectation. The choice of weighting scheme significantly affects downstream analysis: raw co-occurrence counts favor high-velocity items, lift normalizes for popularity but can be unstable for low-frequency pairs, and PMI provides a log-scaled measure that balances these concerns. Graph construction decisions also include the edge threshold (minimum co-purchase frequency or significance level required to create an edge), which controls graph density. Very dense graphs obscure meaningful affinities in a sea of weak connections, while overly sparse graphs fragment the network and lose indirect affinity paths. Temporal weighting, which discounts older co-purchases relative to recent ones through exponential decay, ensures the graph reflects current consumer behavior rather than historical patterns that may no longer hold. askbiz.co constructs dynamically weighted product affinity graphs from PoS transactions, updating edge weights incrementally as new transactions are processed.

Graph Neural Network Architectures for Affinity Learning

Graph neural networks (GNNs) operate on graph-structured data by iteratively aggregating and transforming information from each node neighborhood, learning distributed vector representations (embeddings) that encode both node features and graph topology. The Graph Convolutional Network (GCN) architecture, introduced by Kipf and Welling (2017), computes node embeddings through spectral convolutions that average neighbor features weighted by the normalized adjacency matrix. GraphSAGE (Hamilton, Ying, and Leskovec, 2017) generalizes this through a learnable aggregation function — mean, max-pool, or LSTM-based — that samples from each node neighborhood, enabling inductive learning on unseen nodes (new products). Graph Attention Networks (GAT) introduce attention mechanisms that learn to weight neighbor contributions differentially, allowing the model to focus on the most relevant co-purchase relationships for each product. For product affinity discovery, the GNN is typically trained with a link prediction objective: given a graph with some edges held out, the model learns embeddings such that products connected by edges have similar representations while unconnected products have dissimilar representations. The trained embeddings then encode rich affinity information that can be queried through nearest-neighbor search in the embedding space. askbiz.co employs lightweight GNN architectures to learn product embeddings from co-purchase graphs, enabling affinity discovery that captures multi-hop relationships beyond what pairwise association rules can reveal.

Applications: Cross-Selling, Assortment, and Layout

Product embeddings learned by GNNs on co-purchase graphs support several high-value retail applications. Cross-selling recommendations derived from embedding similarity surface products that are related through complex co-purchase patterns, not just direct pairwise associations. A product whose embedding is close to items in a different category suggests cross-category affinity that would not be discovered through within-category association analysis. Assortment optimization benefits from embeddings that reveal product clusters and gaps: densely connected clusters of frequently co-purchased items represent core product groups that should be stocked together, while isolated products with weak graph connections may be assortment candidates for removal or replacement. Store layout and planogram optimization can use embedding similarity to identify products that should be placed in proximity to encourage basket building, with the GNN capturing indirect placement relationships that simple co-purchase analysis would miss. New product cold-start recommendations, where a newly introduced item has no co-purchase history, can be generated by computing the new product embedding from its node features (category, price point, brand) using the inductive capabilities of GraphSAGE-type architectures. askbiz.co translates product embedding similarities into actionable cross-selling suggestions displayed at the PoS terminal, prompting staff to suggest related items during checkout interactions.

Evaluation and Practical Considerations

Evaluating product affinity models requires metrics that capture both statistical accuracy and business relevance. Link prediction metrics such as AUC-ROC and Average Precision measure how well the model recovers held-out co-purchase edges, testing whether learned embeddings capture the observed graph structure. However, statistical performance on link prediction does not guarantee business value: a model that accurately predicts existing co-purchase patterns may simply recapitulate well-known associations rather than surfacing novel, actionable insights. Business-relevant evaluation should assess whether GNN-derived recommendations generate incremental basket value compared to baseline cross-selling approaches (pairwise rules, category-based suggestions, or no recommendations). A/B testing of cross-selling prompts derived from GNN embeddings versus traditional methods provides causal evidence of incremental value. Computational considerations for small retailers favor lightweight architectures with two to three GNN layers and embedding dimensions of 32 to 64, which can be trained on modest hardware in minutes for graphs with thousands of product nodes. Retraining frequency depends on the rate of assortment change and demand evolution, with monthly retraining sufficient for most stable retail environments. askbiz.co retrains product affinity models monthly, evaluating embedding quality through held-out co-purchase prediction and tracking the conversion rate of GNN-derived cross-selling suggestions at the point of sale.

Related Articles

Clustering Retail Locations by Operational Performance: Unsupervised Methods for Multi-Store PoS Portfolios10 min · IntermediateFeature Engineering for Machine Learning on Point-of-Sale Data: A Practitioners Taxonomy10 min · IntermediateCausal Inference for Promotion Effectiveness: Disentangling Lift From Seasonality in PoS Transaction Data10 min · Advanced