简体   繁体   English

验证准确性如何确定Keras二进制分类中哪个类别正确?

[英]How does the validation accuracy decide which class is correct in a binary classification with Keras?

I've been using Keras for binary classification with Tensorflow backend in Python. 我一直在使用Keras在Python中使用Tensorflow后端进行二进制分类。 My model is created like this : 我的模型是这样创建的:

model = Sequential()
model.add(Dense(1000, input_dim=168319))
model.add(Dense(units=1, activation='sigmoid'))
model.compile(loss="binary_crossentropy",
          optimizer="adam",
          metrics=['accuracy'])

And my result after training looks like this : 训练后的结果如下:

342/1342 [==============================] - 79s 59ms/step - loss: 0.0586 - acc: 0.9911 - val_loss: 0.4632 - val_acc: 0.8169

If I use my network to predict a sample, it gives me a number between [0,1], as it should, since I'm using a sigmoid activation function for my output neuron. 如果我使用我的网络来预测样本,它会给我一个介于[0,1]之间的数字,因为我对输出神经元使用了S型激活函数。 One example of what my output looks like after a prediction for 6 samples which should be of class 1 : 在预测了应该属于1类的6个样本之后,我的输出看起来像一个例子:

[[1.        ][1.        ][0.99997437][0.18694757][0.18712251][0.9491884 ]]

Since the results are all floats between 0 and 1 , I've been wondering how Keras calculates the validation accuracy. 由于结果都是介于0和1之间的浮点数,因此我一直想知道Keras如何计算验证准确性。 Validation accuracy is measured with testing samples that are not used for training. 验证准确性是通过未用于培训的测试样本来衡量的。 As mentioned here how does Keras compute validation accuracy and training accuracy? 如此处所述,Keras如何计算验证准确性和训练准确性? , the validation accuracy is calculated with (amount of correct guesses)/(total amount of guesses) . ,验证准确性的计算方法是(amount of correct guesses)/(total amount of guesses)

My Question here is, how does Keras decide which class the guess belongs to, when is it "correct". 我的问题是,Keras如何确定猜测所属的类别,何时是“正确”的。 Does it round up at 0.5? 舍入为0.5吗? Or is everything between 0 and 1 classified as "wrong guess" (Would expect a way lower number in validation accuracy then)? 还是将0到1之间的所有内容归类为“错误猜测”(届时期望验证准确性的数字会更低)?

Since you are using binary_crossentropy , in this case each of your six classes is evaluated separately. 由于您使用的是binary_crossentropy ,因此在这种情况下,六个类别的每个类别都将分别进行评估。 For each a value above 0.5 is set to 1. Below 0.5 is set to 0. If you were using categorical_crossentropy then only one of the classes can be 1. Whichever has the highest probability will be set to 1. The rest will be set to 0. If you think about it, the binary case is just a special case of the categorical one. 对于每个值,将大于0.5的值设置为1。小于0.5的值设置为0。如果您使用categorical_crossentropy则只有一个类可以为1。将概率最高的一个设置为1。将其余的设置为0.如果考虑一下, binary情况只是categorical情况的一种特殊情况。 The highest value is set to 1. So if and only if the prediction is bigger than 0.5 then the prediction is set to 1. 最大值设置为1。因此,当且仅当预测值大于0.5时,预测值才设置为1。

For more info, see binary_accuracy under github.com/keras-team/keras/blob/master/keras/metrics.py. 有关更多信息,请参见binary_accuracy下的binary_accuracy。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Keras 验证准确度为 1,但在二进制分类中仅预测 class 0? - Keras validation accuracy is 1 but only predicts only class 0 in binary classification? Keras 如何计算多类分类问题的验证准确率和训练准确率? - How does Keras compute validation accuracy and training accuracy for multi-class classification problems? 训练精度高,验证精度低 CNN二元分类 keras - High training accuracy, low validation accuracy CNN binary classification keras 如何在 Keras 中显示多类图像分类任务的验证精度? - How to display validation accuracy for multi-class image classification tasks in Keras? 如何在训练过程中纠正不稳定的损失和准确率? (二元分类) - How to correct unstable loss and accuracy during training? (binary classification) Keras 在二元分类问题中准确率停留在 50% - Keras accuracy stuck at 50% in a binary classification problem Keras图像分类验证精度更高 - Keras image classification validation accuracy higher Keras 精度在 model 和二进制 output 的分类报告之间存在差异 - Keras accuracy is different between model and classification report for binary output Keras 中的自定义指标用于计算回归任务中的二元分类准确度 - Custom metric in Keras to calculate binary classification accuracy in regression task 为什么我在 Keras 二进制分类 model 中的精度为零? - Why I'm getting zero accuracy in Keras binary classification model?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM