how to write a custom loss function in keras regression where MAE is calculated for y_pred above a certain threshold only.
For eg. y_true = [10 , 14 , 23 , 30 , 5 , 4] ,
y_pred = [8 , 12 , 27 , 38 , 10 , 8]
How to write a custom loss function where MAE(Mean absolute error) of y_pred values above 20 only are calculated i.e MAE for y_pred > 20 i.e [23,30] which comes to 6 [(27-23) + (38-30)]/2
This problem has arisen as i need models that predict correctly only the highest range of predictions so that i can use only those data points only that return the highest predictions as rest of the lower predictions data is not useful for me. something like -
def custom_loss(y_pred, y_true):
for y_pred > 20:
result =MAE(y_pred , y_true)
return result