Search code examples
pythontensorflowmachine-learningkerasloss-function

How to increase the loss if the predicted value is less than the label but not if it is greater


I use an ai model to make a prediction of a value using mse. Do to noise in the data set, it is impossible for the model to ever give a perfect prediction. What I want to do is if there are two predictions equidistant from a label I want the lower prediction to be assigned a greater loss compared to the greater one. Essentially I want the model to be more likely to overshoot the value than to undershoot.

I assume this is done when compiling a model.

How would I modify this code segment used to compile my model to accomplish this?

genModel.compile(optimizer='adam',
              loss='mean_squared_error',
              metrics=['mae', 'mean_squared_logarithmic_error'])

Solution

  • You can create your own custom loss function according the api reference and compile your model with it. If you are using tenserflow you can refer to its implementation of mean squared error loss and modify it according to your need.