1
$\begingroup$

I have a set of sales transaction data containing more than 1 item purchased. Every item sold has a category. I would like figure out which categories are most commonly ordered together.

The data is more or less like this:

Transaction ID|Item ID | Sales Quantity|Item Category
1              Apple     1              Fruit
1              Banana    1              Fruit
1              Carrot    2              Vegetable
2              Carrot    1              Vegetable
2              Ice Cream 2              Dessert
3              Squash    2              Vegetable
3              Chocolate 2              Dessert
4              Apple     1              Fruit
4              Carrot    1              Vegetable
4              Doughnut  1              Dessert

Just eyeballing above you can see that there are a high amount of vegetable-dessert pairings on the same transaction. But now imagine that we have 250,000+ transactions in the data set and dozens of categories. I'm looking to discover cross category sales only. Not interested in Apples and Bananas (Fruit-Fruit) pairs.

I think I can teach myself how to code the analysis, but I'm just not sure what this is called or what to Google. Any thoughts?

$\endgroup$
1
$\begingroup$

Note that your data can be re-ordered to look like this:

Transaction ID | Items
1                {Apple, Banana, Carrot}
2                {Carrot, Ice Cream}

This kind of data set is trivial for association rule mining. A very simple and well-known algorithm of this kind is the Apriori. I'm certain there are packages for executing this algorithm in R.

For the restriction of "discover cross category sales only", you can just post-prune the generated rules, ie. let the algorithm generated inter-category sales and then remove those later, which should be trivial.

$\endgroup$
0
$\begingroup$

Based on @Mephy's answer, I wanted to illustrate a little bit more. Association rule mining, which is also called 'Market Basket Analysis'.

Based on your question, Googling market basket analysis will give you more results and there are many examples and posts on getting started in R.

For example arules is a great package for this type of analysis in R. Good luck!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.