My regression should predict values >=0 But a wrongly predicted value >0(e.g. 0.001 instead of 0) is much worse then a a slight missprediction of 0.001 (e.g. 0.002 instead of 0.003)

I am thinking about a costume loss function that weights the false non zeros to return a big loss.

Is there a more elegant way ?


this is my unelegant sollution:

def custom_loss(y,yh):
    if y == 0:
        loss = tf.math.minimum(100,yt*100000)
    else :
        loss = losses.mean_squared_error(yh,y)

    return loss
  • 1
    $\begingroup$ I think you have to be very clear on why you want to do this. A regression gives you a conditional expectation, IE an average value, whereas you seem almost to perform a classification. So I am sure there is a more elegant way once you explain what the overall goal is. $\endgroup$ – seanv507 Aug 24 '19 at 15:49
  • $\begingroup$ it almost seems like a classification. I want to predict the amount of land usage by an agent. but the model sometimes predicticts tiny land usages which are totally unreasonable. Is another approach to encompass model standard deviation and set every prediction zero within 0+stdDev? $\endgroup$ – Alexander Vocaet Aug 26 '19 at 7:25
  • 1
    $\begingroup$ I would say thresholding would be a natural approach, yes... but it depends what the prediction is for. you migth also look at hurdle models.stata.com/stata14/hurdle-models $\endgroup$ – seanv507 Aug 26 '19 at 9:22

One option would be Huber Loss which could be setup to increase the weight for some types of errors compared to other errors.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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