I have a dataset of articles metadata for each article, so something like this:

product_id color type
1234 red t-shirt

and another containing the transactions of customers, which looks like this:

date customer_id product_id
12/12/12 abcd 1234

Using the second dataset, I was able to determine which products are often bought together. As such, for each product, I have a sorted list of 10 (different) products (at most, it could be less) that are most frequently bought with it. This information is stored in a dictionary of the following form:

{1234: [5678,6352,3434,34433, ...], 1435 : [7832, 9801, 1234], ...}

My question is the following. Is there a way for me to create embeddings of products such that a given product is "close" to the products it is most frequently bought with ? In other words, I want to cluster articles that are bought together in a space and have vectors (embeddings) for each product.

Why would I want to do this ?

  1. To see if I can see an interesting structure in my data
  2. To recommend items to users, I can look for the k-nearest neighbors of the users' latest purchases

It looks to me like it is some form of supervised clustering (if that even makes sense), but I can't exactly find how I would go about doing this.

If you could point to me towards an algorithm or something I am missing here, please let me know.


1 Answer 1


This is a straightforward use case for collaborative filtering.

  1. Transform your customer transactions dataset so that you have a matrix where each row is a customer, each column is a product, and the value of each cell is 1 of that customer has bought that product, and 0 otherwise.
  2. Train a collaborative filtering model on your data. This will result in one matrix with a vector per customer, and another matrix with a vector per product.
  3. Cluster the vectors from the product matrix.

Caveat: this method does not leverage any of the information in your articles metadata table.


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.