The following is what I'm trying to accomplish:

I have a charity contact data set. Each contact has features such as sex, age and so on, which we define as X.

Now we are doing a solicitation campaign: we send mails to certain contacts, with a cost of 5 dollars per person, and they can respond by making a donation of however much money they wish. For the training set, we have the persons that have received the mails, and Y_amount is the amount they donated (0 if they didn't do so). People who didn't receive the mails couldn't make unsolicited donations.

Our objective is to maximize the amount raised by the campaign after deducting the cost. However, here comes the tricky part: how could I write a loss function out of this problem and implement it within python?

My original thought was to train a neural network that gives the confidence of generating net revenues from each person Y_confidence on X using the following loss function (the money we could raise if I follow the rule):

  • Y_decision = 1 if Y_confidence > 0.5
  • Y_decision = 0 if Y_confidence < 0.5
  • Loss = -SUM(Y_decision * (Y_amount - 5))

Do you know how to implement it or do you have a better idea of solving this problem?

  • $\begingroup$ Just sharing what I quick thought of when reading your post: maybe Uplift Modeling that is used in marketing can be used here. Uplift models seek to predict the incremental value attained in response to a treatment. See these two blogposts by Wayfair: tech.wayfair.com/data-science/2018/10/…, and tech.wayfair.com/data-science/2018/05/…. You may find this kind of modeling useful for your use case. Surely need to spend a bit time to understand it first. $\endgroup$ Commented Oct 21, 2019 at 4:59
  • $\begingroup$ Hi. Are you sure the uplift model is applicable to my problem? In my dataset, people can't make donations if they didn't receive a treatment, but the uplift model assumes that people can do so even without a treatment, although less likely than with one. $\endgroup$
    – Mone
    Commented Oct 21, 2019 at 6:44
  • $\begingroup$ I would not be sure at all. I was thinking loud as I said. But I would give up on that, because there well-established model you an use. I was not aware of 'people can do so even without a treatment'!! $\endgroup$ Commented Oct 21, 2019 at 9:30

1 Answer 1


You can break the problem into two separate problems:

  1. How much is a person likely to donate? That is a regression problem.

  2. How to maximize the amount raised by the campaign after deducting the cost? That is contraine optimization problem.

Each separate problem can be solved with existing tools without creating a custom loss function.


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.