How do we make recommendations in our lives ? We do it based on our past experiences. Now imagine, what if we start making instant recommendations based on data in our real lives? First, we’ll feel like an intelligent adviser. Second, we will no longer be humans. Therefore, we aim to build intelligent softwares, which are capable of providing cogent recommendations.
We are sub-consciously exposed to recommendation systems when we visit websites such as Amazon, Netflix, imdb and many more. Apparently, they have become an integral part of online marketing (pushing products online). Let’s learn more about them here.
In this article, I’ve explained the working of recommendation system using a real life example, just to show you this is not limited to online marketing. It is being used by all industries. Also, we’ll learn about its various types followed by a practical exercise in R. The term ‘recommendation engine’ & ‘recommendation system’ has been used interchangeably. Don’t get confused!
Today, every industry is making full use of recommendation systems with their own tailored versions. Let’s take banking industry for an example.
Bank X wants to make use of the transactions information and accordingly customize the offers they provide to their existing credit and debit card users. Here is what the end state of such analysis looks like:
Customer Z walks in to a Pizza Hut. He pays the food bill through bank Xs card. Using all the past transaction information, bank X knows that Customer Z likes to have an ice cream after his pizza. Using this transaction information at pizza hut, bank has located the exact location of the customer. Next, it finds 5 ice cream stores which are close enough to the customer and 3 of which have ties with bank X.
This is the interesting part. Now, here are the deals with these ice-cream store:
Store 1 : Bank profit – $2, Customer expense – $10, Propensity of customer to respond – 20%
Store 2 : Bank profit – $2, Customer expense – $10, Propensity of customer to respond – 20%
Store 3 : Bank profit – $5, Customer expense – $12, Propensity of customer to respond – 20%
Store 4 : Bank profit – $6, Customer expense – $12, Propensity of customer to respond – 20%
Store 5 : Bank profit – $4, Customer expense – $11, Propensity of customer to respond – 20%
Let’s assume the marked prize is proportional to the desire of customer to have that ice-cream. Hence, customer struggles with the trade-off that whether to fulfil his desire at the extra cost or buy the cheaper ice cream. Bank X wants the customer to go to store 3,4 or 5 (higher profits). It can increase the propensity of the customer to respond if it gives him a reasonable deal. Let’s assume that discounts are always whole numbers. For now, the expected value was :
Expected value = 20%*{2 + 2 + 5 + 6 + 4 } = $ 19/5 = $3.8
Can we increase the expected value by giving out discounts. Here is how the propensity varies at store (3,4,5) varies :
Store 3 : Discount of $1 increases propensity by 5%, a discount of $2 by 7.5% and a discount of $3 by 10%
Store 4 : Discount of $1 increases propensity by 25%, a discount of $2 by 30%, a discount of $3 by 35% and a discount of $4 by 80%
Store 5 : No change with any discount
Banks cannot give multiple offers at the same time with competing merchants. You need to assume that an increase in ones propensity gives equal percentage point decrease in all other propensity. Here is the calculation for the most intuitive case – Give a discount of $2 at store 4.
Expected value = 50%/4 * (2 + 2 + 5 + 4) + 50% * 5 = $ 13/8 + $2.5 = $1.6 + $2.5 = $4.1
Think Box : Is there any better option available which can give bank a higher profit? I’d be interested to know!
You see, making recommendations isn’t about extracting data, writing codes and be done with it. Instead, it requires mathematics (apparently), logical thinking and a flair to use a programming language. Trust me, third one is the easiest of all. Feeling confident? Let’s proceed.
Previous example would have given you a fair idea. It’s time to make it crystal clear. Let’s understand what all a recommendation engine can do in context of previous example (Bank X):
There are broadly two types of recommender engines and based on the industry we make this choice. We have explained each of these algorithms in our previous articles, but here I try to put a practical explanation to help you understand them easily.
I’ve explained these algorithms in context of the industry they are used in and what makes them apt for these industries.
Good question! We must know that performance metrics are strongly driven by business objectives. Generally, there are three possible metrics which you might want to optimise:
Let’s get some hands-on experience building a recommendation engine. Here, I’ve demonstrated building an item-item collaborative filter recommendation engine. The data contains just 2 columns namely individual_merchant and individual_customer. The data is available to download – Download Now.
The code is easy to understand. Hence, I haven’t explained it explicitly. If you find any part of code hard to understand, ask me in comments section below.
#load libraries
> library(plyr)
> library("arules")
> library(readr)
#load data
#This file has two columns inidividual_merchant and inidividual_customer
> input <- read_csv("Transaction_file.csv")
#Get the list of merchants/items
> merchant <- unique(input$individual_merchant)
> merchant <- merchant[order(merchant)]
> target_merchants <- merchant
> sno <- 1:length(target_merchants)
> merchant_ident <- cbind(target_merchants,sno)
#Create a reference mapper for all merchant
> colnames(merchant_ident) <- c("individual_merchant","sno")
# Create a correlation matrix for these merchants
> correlation_mat = matrix(0,length(merchant),length(target_merchants))
> correlation_mat = as.data.frame(correlation_mat)
> trans = read.transactions("Transaction_file.csv", format = "single", sep = ",", cols =
c("inidividual_customer", "individual_merchant"))
> c <- crossTable(trans)
> rowitem <- rownames(c)
> columnitem <- colnames(c)
> correlation_mat <- c[order(as.numeric(rowitem)),order(as.numeric(columnitem))]
> for(i in 1:9822) {
correlation_mat[i,] <- correlation_mat[i,]/correlation_mat[i,i]
}
> colnames(correlation_mat) <- target_merchants
> rownames(correlation_mat) <- merchant
# Now let's start recommending for individual customer
> possible_slots <- 20
> avail <- 21
> merch_rec <- matrix(0, nrow = length(target_customers), ncol = avail)
> merch_rec[,1] <- unique(input3$Cust_map)
> correlation_mat <- as.matrix(correlation_mat)
> position <- 1
> for (i in 1:length(target_customers)) {
been_thr <- input[position : (position + customer_merch_ct[i] - 1),'individual_merchant']
merging <- as.data.frame(merchant_ident[merchant_ident[,'individual_merchant'] %in% been_thr,])
corel_subset <- correlation_mat[merging$sno,]
will_go <- colSums(corel_subset)
will_go_merch <- target_merchants[order(-will_go)]
not_been_there <- will_go_merch[!will_go_merch %in% been_thr]
will_go_propensity <- will_go[order(-will_go)][!will_go_merch %in% been_thr]
merch_rec[i,2:avail] <- not_been_there[1:possible_slots]
position <- position + customer_merch_ct[i]
}
Recommended engines have become extremely common because they solve one of the commonly found business case for all industries. Substitute to these recommendation engine are very difficult because they predict for multiple items/merchant at the same time. Classification algorithms struggle to take in so many classes as the output variable.
In this article, we learnt about the use of recommendation systems in Banks. We also looked at implementing a recommendation engine in R. No doubt, they are being used across all sectors of industry, with a common aim to enhance customer experience.
Did you like reading this article ? Have you built a recommendation system in past? Do share your experience / suggestions in the comments section below.
Wish you had made the dataset available to everyone in order for us (i.e. readers) to get some hands-on practice.
An actual dataset will be very difficult to be made public. However, to understand the underlying concept, you can create a cvs named "transaction_file" with just two columns : individual_customer and individual_merchant. Generate random numbers from 1 to 100 in 1st column and from 1 to 10 in second column. Create this table for about 500 rows. Now remove duplicate and you have a transaction table ready. We will try to get you this sample data on the forum as well. Thanks for reading. Tavish
Hi where do you get the file Transaction_file.csv ? You may email me.
An actual dataset will be very difficult to be made public. However, to understand the underlying concept, you can create a cvs named "transaction_file" with just two columns : individual_customer and individual_merchant. Generate random numbers from 1 to 100 in 1st column and from 1 to 10 in second column. Create this table for about 500 rows. Now remove duplicate and you have a transaction table ready. We will try to get you this sample data on the forum as well. Thanks for reading. Tavish
please email me the data file
An actual dataset will be very difficult to be made public. However, to understand the underlying concept, you can create a cvs named "transaction_file" with just two columns : individual_customer and individual_merchant. Generate random numbers from 1 to 100 in 1st column and from 1 to 10 in second column. Create this table for about 500 rows. Now remove duplicate and you have a transaction table ready. We will try to get you this sample data on the forum as well. Thanks for reading. Tavish
Hi where do you get the file Transaction_file.csv ? You may email me. [email protected]