I would like to find a good model to predict which client will buy my product in 2018. I would like to have opinions on which method can fit my data to predict which client will the product A in 2018. The data is a picture at a certain date, thus I think that time series models are not applicable ?!

I have the following data:

client buyproductin17 buyproductin16 buyproductin15 all_day  day_cnt product 
 22         1               0              1           34      5       2
 23         0               1              1           56      11      2
 24         1               1              1           122     45      3

client = client ID

buyproduct17 = if the client buy the product A in 2017 or not

buyproduct16 = if the client buy the product A in 2016 or not

buyproduct15 = if the client buy the product A in 2015 or not

all_day = total number of day the client spent with all my product

day_cnt = total number of day the client spent with product A

product = total number of product A the client has

My first thought are a logistic regression model or a random forest. But which dependant variable can I use ? buyproductin17 ?

Thanks a lot



1 Answer 1


So I think there are a couple of options, but they may depend on how much data you have. You could try a model in the random forest family, preferably with boot-strap aggregation (i.e., "bagging"). Random forest models and other decision-tree rooted (pun intended) models and their extensions (e.g., gradient boosting machines), can handle 0,1 outcome data, but testing the predictive utility of these models requires that you have a large enough data set that you can split your data into training and testing sets to evaluate the effects of changes you make to the hyperparameters of the model (i.e., number of trees, interaction depth, learning rate if applicable).

Given that you are largely interested in effective predictions from your model, you are almost certainly going to have to perform a testing/training split no matter the approach you settle on.

With a logistic regression, you have to specify the model up front that you think best accounts for your log odds (i.e., logits - what the model transforms your probability of purchase variable into). You can specify all interactions between your predictors in your model upfront, and really your goal here is just to maximize the model's ability to predict purchase rates this year.

I would recommend trying both approaches and seeing which is more accurate... but accuracy is going to be your problem. You do not have a 2018 purchase variable it looks like. At least I do not see one in the data above. Therefore, there is no way to test if your model performs well given observed data in 2018.

This is a common problem in forecasting, we know very little about future scores in a data set and therefore have to make some assumptions (i.e., trends continue, trends level off, there is a periodic component, etc.). In your case, I would say the best option would be to fit a model to 2017 data, optimize it for prediction that year by comparing a trained model against a held-out testing sample (i.e., data that the model has not yet "seen"), and then predict 2018 using the same variables shifted one year up (if they were measured yearly).

Because your data appears nested within-subject, you also have the option of conducting a generalized linear mixed effects model (in your case an extension of your logistic regression but with random effects).

In R, the base stats package provides you a glm function that can be used to fit a straightforward logistic regression. The randomForest and gbm libraries are good places to start for the use of more advanced decision tree models. Finally, the lme4 package has a glmer function that you can use to create mixed effects model for your data. I would say that this last option is going to be the most difficult to apply to your current situation as the data would need to be reshaped (stacked as opposed to wide) and you will have to think more carefully about how to implement training/testing splits.

  • $\begingroup$ Thanks a lot for this detailed answer ! My dataset is very large. Thus, I split my in train and test sets (75%,25%). I have computed the accuracy with both model and to be very precise I did a cross validation. At the end the logistic regression seams to have better predictions capabilities. As you said I did not have 2018 values. Thus, I have decided to compute both models with 2017 values as dependant variable. $\endgroup$
    – D.Dupont
    Dec 11, 2018 at 10:56
  • 1
    $\begingroup$ Sounds good. And with all the machine learning options out there people forget how effective a good logistic regression can be. A simple, but effective tool that predates are machine learning/AI revolution. $\endgroup$ Dec 11, 2018 at 14:24

Your Answer

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

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