Passing group id to custom loss function

Skip to first unread message

Harry Cutler

Jun 5, 2023, 2:50:38 AMJun 5
to Keras-users
Hi Keras users,

I was hoping that someone might be able to give me a hand.

I've been using keras to model a disease risk factor in 11 different populations and am trying to create a custom loss function that is aware of these population groups.

Currently training the model with mse as the loss function, but I would like to encourage the model to condense the variation in its predictions for specific groups. Specifically, the screenshot below shows model performance where each colour represents a different population group. As an example, the green group is much narrower than the blue and purple group, suggesting that the model has done a better job learning that group. I would like to create a loss function to explicitly encourage the model to condense variation on the x-axis, however, I'm having trouble passing group ids to the loss function back end.

Is anyone able to suggest a workaround? I'd be incredibly grateful for any help that you are kind enough to provide. Please let me know if you have any questions.


Kind regards,

Alberto Matuozzo

Jun 11, 2023, 12:42:51 PMJun 11
to Harry Cutler, Keras-users

What about simply using group id as a feature in the model?

You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages