Normally when I train a random forest to classify observations into multi-class buckets the objective is to correctly predict which bucket an observation will fall into based on historical (training) data.

Instead, I want to train the random forest to classify observations on some other criteria, such as profit maximization. Is this possible?

Here's an example:

Imagine that we have data on Dropbox subscriptions over the past 1 year. Some Dropbox leads (potential customers) had 1 of 3 possible coupons, other leads did not have a coupon.

In this scenario I want to determine which (if any) coupon I should should offer to a lead to maximize net revenue, considering their likelihood of purchasing a subscription, their predicted retention (# of months they will continue their subscription) and the effect of the coupon on purchase price.

Theoretically some leads who are likely to purchase a subscription and be retained will not need a coupon to do so. Others might produce higher net revenue from a coupon for "$5 off per month" or "first month free", etc.

I presume the dependent variable should still be coupon type, i.e.

Y = No Coupon, Coupon A, Coupon B, Coupon C, Coupon D

Is it possible to make the random forest work in this way? You can consider this question language-agnostic, though if I have a choice I will try to do this in R.

I know that in the case of eXtreme Gradient Boosting in either R or Python I can specify a custom objective function.


1 Answer 1


Your target variable should always reflect what you're trying to optimize (maximize or reduce), so if you want to maximize revenue, you should make revenue your target variable. I would use the coupons as independent variables. When you want to see whether to offer a coupon or not for a particular customer, feed a new record into your model for every permutation of coupon / no coupon and see which has the highest prediction. There might be other/better ways of doing this, but I think this should get what you're looking for.

  • $\begingroup$ But I'm trying to decide which coupon to offer based on profit maximization, allowing for individual level variation based on demographics and other data. $\endgroup$
    – Hack-R
    Aug 9, 2016 at 22:40
  • $\begingroup$ I know that in the case of eXtreme Gradient Boosting in either R or Python I can specify a custom objective function. This is just a different tree model, so I should be able to do the same, no? $\endgroup$
    – Hack-R
    Aug 10, 2016 at 3:08
  • $\begingroup$ @HackR I suppose, but that seems like a more indirect way of doing it. To me it sounds simpler to just use a default loss/objective function (like mean absolute error), and just make your target variable more relevant. By the way, you can use any model, not just tree models. $\endgroup$
    – Ryan Zotti
    Aug 10, 2016 at 12:46

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.