how to convert logits to probability in binary classification in tensorflow?

余生长醉 提交于 2021-02-18 10:59:10

问题


logits= tf.matmul(inputs, weight) + bias

After matmul operation, the logits are two values derive from the MLP layer. My target is binary classification, how to convert the two values, logits, into probabilities, which include positive prob and negative prob and the sum of them is 1 ?


回答1:


predictions = tf.nn.softmax(logits)



回答2:


I am writing this answer for anyone who needs further clarifications:

If it is a binary classification, it should be:

prediction = tf.round(tf.nn.sigmoid(logit))

If it is a multi-class classification:

prediction = tf.nn.softmax(logit)

then using the argmax function you can get the index of the class that has the highest probability score.

np.argmax(prediction, 0)


来源:https://stackoverflow.com/questions/46416984/how-to-convert-logits-to-probability-in-binary-classification-in-tensorflow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!