Machine Learning: Association Rule Mining

Users who bought this… Also bought this…‘, I consider this as the statement of this generation. There is not a single shopping application not showcasing this feature to gain more from the buyers. This rule is another by-product of Machine Learning. We humans always look for more similar things which we like for example if a reader starts to like a book of the specific genre say ‘biography’ he/she is leaned towards having more such similar books. And this is what we call ‘associate’. User associates more such books of biography as an interest of reading the genre which he liked and this algorithm is widely used today by shopping sites to recommend users with similar items they liked with what we call as ‘Association Rules’. This not only finds its application to recommend a bundle of things which are bought together or seen together on shopping sites but also this is used to place the bundled items together on the store shelves or maybe to make better navigation to redesign websites.

Understanding Association Rule

As I mentioned it is a by-product of Machine Learning, and is impossible to implement without data. In association, there is a sea of data of user ‘transactions’ and seeing the trend in these transactions that occur more often are then converted into rules. Let’s break it down; ‘Transaction’ can be a single shopping cart, the web pages visited by the user during a web session, in general transactions are actions of our customers and the items/objects which are viewed by the users are referred to as items or item-sets of the transactions. These can also be referred to as cart/baskets/bundles with respect to shopping analogy.

Association Rule Mining is thus based on two set of rules:

  1. Look for the transactions where there is a bundle or relevance of association of secondary items to the primary items above a certain threshold of frequency
  2. Convert them into ‘Association Rules’

Let us consider an example of a small database of transactions from a library

0. The Hobbit, The Princess Bride
1. The Princess Bride, The Last Unicorn
2. The Hobbit
3. The Never-ending Story
4. The Last Unicorn
5. The Hobbit, The Princess Bride, The Fellowship of the Ring
6. The Hobbit, The Fellowship of the Rings, The Two Towers, The Return of the King
7. The Fellowship of the Ring, The Two Towers, The Return of the King
8. The Hobbit, The Princess Bride, The Last Unicorn
9. The Last Unicorn, The Never-ending Story

Let us form rules, The Hobbit is in 50% of the transactions in the above listing 5/10. The Princess Bride is 40% of the times 4/10. And both together are bought 30% of the time 3/10. We can say that the support of {The Hobbit, The Princess Bride} is 30%. Out of 5 transactions of The Hobbit 60 % i.e. 3/5 transactions are for The Princess Bride. This 60% is the confidence of the rule we just formed. Thus, we formed a rule that supportThe Hobbit and The Princess bride 30% of the times with confidence being 60%. This states 30% of all the transactions we see are possibly both being bought together. And if The Hobbit is bought, there is 60% chance user might also buy The Princess Bride. Thus, we associate ‘Users who bought The Hobbit, Also bought The Princess Bride’ at the checkout.

The rule is also applicable conversely whenever The Princess Bride was bought 40% of all transactions 4/10. The Hobbit appeared 3 times 3/4 i.e. 75% of the time. Thus, ‘Users who bought The Princess Bride also bought The Hobbit’, for this rule we have support of 30% of all the transactions and confidence of 75%. We can conclude support and confidence form the basis of association rules. To mathematically define support and confidence consider X and Y are our items in Association i.e. ‘Users who bought X also bought Y’ where X is our Primary item and Y is our secondary/associated item. Moving on, we our looking this transaction in a transaction set say, T. With these assumptions we have support S = X + Y / T and confidence C = X / Y. There is always minimal benchmark one should set before forming association rules, I always consider support of minimum of 10% and confidence of minimum of 60%. There is no point of associating with support of 5% with confidence of 20%. It is a waste of rule and time used behind forming such rules, ‘over associations’.

With enough exposure to the basics and background of Association Rules, let us now start doing this practically as this is what “The Datum” is known for, giving you the tools and practical algorithms that you need to do things practically and learn from them.

Data for this Algorithm

The data is extracted from the University of Freiburg, from the research they conducted. The data is based on a bookstore database. The data consists of the interests of customers in the books. The information about customer interests in the books is based on their previous purchases and book interests. Purchase is a sign of interest and also the ratings which the users have given also indicates their interest. Thus, for our data transaction is our customers and the item-set is all the books they have expressed interest in, can either be by purchasing or by ratings they left. To implement our rules will be using library package arules and a function in it called apriori, as we cruise further we will better understand the working

To get access to the complete article on Association Rule Mining visit: 
https://thedatum.data.blog/2019/06/09/machine-learning-association-…

By hitting the link above you get complete access to the listings of the algorithm implemented in R with all the relevant outputs. Hit the link above and get ready with R to implement your Association Rules Mining!

Cheers,
The Datum
https://thedatum.data.blog/

AI Magazine | Artificial Intelligence News and Discussions