Shape of graph for co-purchased items

46 Views Asked by At

I have a database containing orders from a e-commerce site where:

    order id      items_purchased
    order_num_1   [a,b,c] 
    order_num_2   [b,d,a] 
    order_num_3   [z,x,y] 

I am confused on the structure of the graph showing the relationship of products to products -- Specifically, if I should take the cartesian product of each order --example for order_num_1

  edge   node 
   a        a
   a        b 
   a        c 
   b        a 
   b        b 
   b        c 
   c        a 
   c        b 
   c        c 

Or if it can be represented simply as :

  edge      node 
  a          a 
  a          b 
  a          c 
1

There are 1 best solutions below

5
On

Just to check my understanding of your question. Here, you want the items in a given purchase to be vertices, and use edges to relate two items if they are in the same order. In that case, why not use a complete graph $K_{n}$? If you wanted to have a self-loop edge for each vertex in the order, you could. I think it would be a bit unnecessary, personally.