Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use log_loss as metric in Keras?

I am using Keras and I want to use logloss as metric for training. How I can pass that into my model?

My code is as follows:

model = Sequential()
model.add(Dense(output_dim=1000, input_dim=390, init='uniform'))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=500, input_dim=1000, init="lecun_uniform"))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=10, input_dim=300, init="lecun_uniform"))
model.add(Activation("sigmoid"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=200, input_dim=10, init="lecun_uniform"))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=100, input_dim=200, init ="glorot_normal"))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=50, input_dim=100, init ="he_normal"))
model.add(Activation("sigmoid"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=2, input_dim=50, init = "normal"))
model.add(Activation("softmax"))
model.compile(loss='binary_crossentropy',optimizer='rmsprop', metrics=['accuracy'])

model.fit(train.values, y1,  nb_epoch=10,
          batch_size=50000, verbose=2,validation_split=0.3, class_weight={1:0.96, 0:0.04})


proba = model.predict_proba(train.values)
log_loss(y, proba[:,1])

How can I pass log_loss in place of accuracy?

like image 530
Kush Patel Avatar asked May 07 '16 03:05

Kush Patel


1 Answers

You already are: loss='binary_crossentropy' specifies that your model should optimize the log loss for binary classification. metrics=['accuracy'] specifies that accuracy should be printed out, but log loss is also printed out by default.

like image 142
1'' Avatar answered Oct 11 '22 21:10

1''