How to do cross validation for multi-label classification task (using cnn or lstm)

133 views
Skip to first unread message

Zhixue Zhao

unread,
Jul 29, 2018, 6:13:47 PM7/29/18
to Keras-users
I am trying to use cross-validation for my CNN model.

I tried cross_val_scores, i guess because the output is probability instead of the label, this method is not workable. 

Also, I tried Kfold, it is kind of like a mess. 

I am thinking if it is possible that the NN output is the label(zero or one) directly instead of a probability.

Thanks.

Sergey O.

unread,
Jul 29, 2018, 6:52:45 PM7/29/18
to Zhixue Zhao, Keras-users
I'm guessing the data is one-hot encoded, and you do softmax for the last activation along with categorical_crossentropy for loss?
If so, you can prob repurpose the categorical_accuracy calculation in keras, where the label is selected based on the index of the max value in both the predicted and input data:
def categorical_accuracy(y_true, y_pred):
  return K.cast(K.equal(K.argmax(y_true, axis=-1),
  K.argmax(y_pred, axis=-1)),
  K.floatx())


--
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 keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/4d3f1dce-6b6d-4caf-a4b5-bfa53c5ec4b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages