# Transaction Log modelling suggestions

I have a data set from a popular online retail site. The customer looks at three different products say product 1, product 2 and product 3 repeatedly over a period of time. The customer checks for prices over the same period and decides to buy product 1 and product 2 and product 3 is not brought. Although the price is the most important factor it’s not the only factor that influences his decision. Assuming that I have the log information on the customer, like how many times the customer did a search for the product or similar type of product and I can group them all together. Can you guys give me a suggestion on how to model this kind of data? If a new search is done I want to predict the likelihood of it turning into a purchase. And I am assuming that the likelihood increases as the number of searches increase until a certain point and then it decreases and eventually the interest in the product wanes off. Thanks for all your help. Let me know I have to elaborate more. here is a sample dataset [Sample data][1]

# Creating the dataset
Product<- c('Guess','LG-TV','Sony-TV','Guess','LG-TV','Sony-TV','Termostat','of men and mice','of men and mice','of men and mice','of men and mice','iphone6','samsung','moto','iphone6','iphone6')
ID<-c(1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3)
Price <- c(25,850,600,26,850,620,40,12,12,12,12, 234,268,400,230,260,)
Date<- as.Date(c('2016-01-1','2016-01-1','2016-01-1','2016-01-02','2016-01-02','2016-01-02','2016-03-14','2016-03-15','2016-03-16','2016-03-17','2016-03-17','2016-01-07','2016-01-07','2016-03-09','2016-03-09','2016-03-10'))
timespent<-c(45,46,32,25,160,20,20,20,11,15,24,8,45,120,26,40)
count<-c(1,1,1,2,2,2,1,1,2,3,4,1,1,1,2,3)
eventually_purchased<-c(0,1,0,0,1,0,0,1,1,1,1,1,0,0,1,1)
Log.data <- data.frame(ID, Product, Date,Price,count,timespent,status,eventually_purchased)
# Finding the difference between the search dates
Log.data<-ddply(Log.data,.(ID,Product),transform,Days=Date-min(Date))


Things I have tried so far. I tried to link the count data to customer buying lifecycle i.e I grouped the data into 4 states "Interest", "Information search","Evaluation" and "buy" so that I have 4 progressive states and I can do something like a survival analysis using Mstate package in R. I couldn't get it to work as many of the items are searched for and bought on the same day.

I hope I have elaborated enough. Thanks for all your help.

## migrated from stackoverflow.comJul 1 '16 at 9:41

This question came from our site for professional and enthusiast programmers.

• you've got any code to show what you've tried? – Jeff Jun 20 '16 at 23:29
• I tried the BTYD package in R. But that gives me the rate at which the customers buy and doesn't tell me the likelihood of a transaction turning successful. I am sorry I don't have any code yet as this is a generalization of the problem I have. – Kish Jun 20 '16 at 23:44

RF <- train(as.factor(last_col) ~., data=training,method="rf",trControl=trainControl(method="cv",number=5),prox=TRUE,allowParallel=TRUE)