且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

混淆矩阵给出了糟糕的结果,但验证准确度约为 95%

更新时间:2023-12-03 23:05:58

假设你的预测数组类似于:

Let's say your predictions array is something like:

preds_sigmoid = np.array([[0.8451], [0.454], [0.5111]])

包含这些值作为 sigmoid 将它们压缩在 [0,1] 的范围内.当您像这样应用 argmax 时,每次都会得到索引 0,因为 argmax 返回指定轴上的最大索引.

containing these values as sigmoid squeeze them in a range of [0,1]. When you apply argmax as you did, you will get index 0 everytime because argmax returns the maximum index at specified axis.

pred = np.argmax(preds_sigmoid , axis = 1) # pred is full of zeros.

您应该评估预测,例如它是否大于某个阈值,例如 0.5,它属于第二类.您可以为此使用列表理解:

You should evaluate the predictions like if it is bigger than some threshold, let's say 0.5, it belongs to second class. You can use list comprehension for this:

pred = [1 * (x[0]>=0.5) for x in preds_sigmoid]

因此将正确处理预测.