Skip to content Skip to sidebar Skip to footer

How To Add Example Based Parameter To Custom Keras Loss Function?

I want to have custom loss function in keras, which has a parameter that is different for each training example. from keras import backend as K def my_mse_loss_b(b): def mseb

Solution 1:

In your case, because your parameter b is tightly coupled to its training example, it would make sense to make it part of the ground truth. You could rewrite your loss function like the following:

def mseb(y_true, y_pred):
    y_t, b = y_true[0], y_true[1]
    return K.mean(K.square(y_pred - y_t)) + b

and then train your model with

model.compile(loss=mseb)
b = df.iloc[:,2]
model.fit(X,(y,b))

Post a Comment for "How To Add Example Based Parameter To Custom Keras Loss Function?"