Getting weighted Loss

Working on assignment 1 week 1 and stumped when calculating weighted loss. I followed the suggestions given to use keras mean and log, but I’m unsure where the mean comes in.

So far, my idea for the loss calculation is

tf.keras.backend.mean((-1 * w_p * y_true * tf.keras.backend.log(y_pred)) + (w_n * (1-y_true) *tf.keras.backend.log(1-y_pred)))

Not completely sure where the epsilon comes in, but I tried adding it to y_pred and that did not work.

Any help would be much appreciated!

Hi @Suraj_Zaveri ,

I will give you some hints to help you solve this exercise:

  1. Keras backend was imported in the notebook as: from keras import backend as K, so please use K
  2. No need to change pos_weights to w_p and neg_weights to w_n
  3. You are looping through i in range len(pos_weights), so use i in your formula

Now, try reworking your loss according to the notes in the notebook.

I hope this helps.

Samuel