如何解释 Keras 预测输出?

数据挖掘 喀拉斯 多标签分类
2022-03-15 13:08:01

我是 Keras 的新手,想在这个数据集上应用神经网络: https ://www.drivendata.org/competitions/57/nepal-earthquake/

我已经使用 pd.get_dummies pandas 方法处理了将分类变量转换为数值的数据集。此外,目标(即 1、2 或 3 - 取决于损坏等级)被转换为三列,指示成为这些值之一的概率。

我写的 NN 很简单,但我不明白 predict 方法返回的值是什么。

# first neural network with keras tutorial
from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense
import tensorflow as tf
import keras.backend as K

# define the keras model
model = Sequential()
# 12 8 3 Accuracy: 57.08
# 25 12 3 Accuracy: 56.89
model.add(Dense(25, input_dim=68, activation='relu'))
model.add(Dense(12, activation='relu'))
model.add(Dense(3, activation='softmax'))
# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=[get_f1])
# fit the keras model on the dataset
model.fit(X, y, epochs=5, batch_size=10)

predicted = model.predict(test)

这是第一个人的输出:

array([0.09522187, 0.57914054, 0.32563758], dtype=float32)

任何的想法?

PD:如果您需要一些额外的信息或代码,请告诉我 :)

非常感谢!!!

1个回答

softmax的输出是一个概率分布,它给出了每一类正确的概率。因此,您必须找出数组中最大值的数组索引。

predicted_class = np.argmax(predicted)