How do I predict a set of frequently bought items?

I have a dataset of retail transactions wherein different users buy certain items together. For example, a user A buys a toothpaste, a toothbrush and a floss at the same time, and a user B buys a toothpaste, a shampoo and a soap together.

I'm required to find out for each item in the dataset a list of items that are frequently bought together with it. For instance, one may expect that whenever a toothbrush is purchased, a toothpaste can be one of the items that are frequently bought together with it.

I tried to make use of the Apriori Algorithm but that would only give me sets of items that are bought together or, I'm unaware if it can somehow be modified to predict frequent purchases for a list of items in the dataset.

Which other algorithm can I put to use here?

Topic predict data-science-model association-rules recommender-system clustering

Category Data Science


The simplest way is to build a matrix representing how often two items are bough together: $M[i,j]$ is the count of how many times items $i$ and $j$ are bought together (note that you need to fill only a diagonal matrix, since it's symmetric).

From there you can calculate whatever you need: most frequent $B$ item bought with a given item $A$, top most frequent pairs of items in general, etc.

You could also consider the matrix as a graph representation, and use algorithms specific to graphs.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.