2
$\begingroup$

We can predict the class for new data instances using the Sequential classification model in Keras using the predict_classes() function. What is the way to predict the class for models that developed using the functional API?

For example, I have a model (functional API based) with sigmoid activation on the last layer to get probabilities in a multi-label classification. When I apply model.predict(), I got a series of probabilities even though the loss is binary_crossentropy.

I understand that I can do this classification manually e.g. following approach.

test_predict_proba = model.predict(x_test, batch_size=batch_size)
class_predict = (test_predicted_proba > 0.5).astype(int)

I am wondering is there any standard procedure to do the same?

$\endgroup$
0
$\begingroup$

Is this a multi-label problem or a pure classification problem? If it is just classification change the activation function in the final layer to softmax. When you do predictions select the output with the highest probability as the class. Alternatively use model.evaluate(.....). versus model.predict Documentation is here,

| improve this answer | |
$\endgroup$
  • $\begingroup$ It's a multi-label classification problem. $\endgroup$ – Mohammad Nur Nobi Apr 29 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.