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')
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'))
Log.data <- data.frame(ID, Product, Date,Price,count,timespent,status,eventually_purchased)
# Finding the difference between the search dates

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.

  • 1
    $\begingroup$ you've got any code to show what you've tried? $\endgroup$
    – Jeff
    Commented Jun 20, 2016 at 23:29
  • $\begingroup$ 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. $\endgroup$
    – Kish
    Commented Jun 20, 2016 at 23:44

1 Answer 1


I'd try a randomForest model. ?randomforest

You can use it as a classification model by passing your last column as a factor. Note that dates could be converted to factors as well, or to numerics.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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